hypercerts-org / hypercerts-org/ePDS
security: metrics endpoint uses non-timing-safe password comparison
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 8
- Forks
- 4
- Avg merge
- 5d 11h
- Merged PRs (30d)
- 3
Description
Problem
The /metrics endpoint in packages/auth-service/src/index.ts:96 compares the admin password using !== (standard string comparison):
```ts
authHeader !== 'Basic ' + Buffer.from('admin:' + adminPassword).toString('base64')
```
This is a timing oracle — the comparison short-circuits on the first differing byte, leaking information about the expected value through response timing.
The rest of the codebase consistently uses crypto.timingSafeEqual() for secret comparisons (CSRF tokens, HMAC signatures, etc.), so this is an inconsistency.
Proposed Fix
Use crypto.timingSafeEqual() for the Basic Auth comparison, with a length check guard:
```ts
const expected = 'Basic ' + Buffer.from('admin:' + adminPassword).toString('base64')
const actual = authHeader ?? ''
if (actual.length !== expected.length ||
!crypto.timingSafeEqual(Buffer.from(actual), Buffer.from(expected))) {
res.status(401).json({ error: 'Unauthorized' })
return
}
```
Severity
Very low — exploiting a timing oracle on a Basic Auth header over a network is impractical, but fixing it is trivial and maintains consistency with the rest of the codebase.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open packages/auth-service/src/index.ts around line 96 and inspect the existing crypto.timingSafeEqual usage elsewhere in the repository. Update the metrics Basic Auth comparison with a length guard, then verify that valid credentials succeed and mismatched headers, including different-length values, return 401.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100