Skip to content

fix: harden auth, logging and dependency floors against recent advisories - #2

Merged
willosof merged 1 commit into
mainfrom
fix/security-hardening
Nov 29, 2026
Merged

willosof merged 1 commit into
mainfrom
fix/security-hardening

Conversation

@willosof

@willosof willosof commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Security hardening following a review of recent Fastify ecosystem advisories.

Changes

  • Raise the @fastify/rate-limit floor to ^11.3.0. The previous ^11.2.2 range still allowed versions affected by GHSA-24mh-2vvh-5r45 (CVE-2026-133312): a race condition in the documented increment: false failed-login flow. This library only uses the default per-request limiter, which isn't affected, but consumers who call that flow on the plugin through app.instance could stay on a vulnerable version with an old lockfile. npm audit doesn't report this advisory yet.
  • Compare static API tokens in constant time. Both tokens are hashed with SHA-256 and compared with crypto.timingSafeEqual, so response timing no longer reveals how much of the token, or its length, an attacker got right.
  • Stop logging rejected response bodies. When response validation fails, only the Zod issues are logged now. The body itself often holds exactly the data that strict validation keeps from being sent, such as passwords or personal data.
  • Warn when a provided Fastify instance is outdated. If config.fastify is older than 5.12.6, the first release without known advisories, a process warning is emitted (code BITFOCUSAS_API_OUTDATED_FASTIFY). A process warning is used because the Fastify logger is often disabled on custom instances.

Checked and not affected

  • fastify ^5.12.8 is above every patched version, including GHSA-389g-gv7q-r4x8 (fixed in 5.12.6) and the advisories fixed in 5.12.2.
  • On a fresh install, @fastify/static (10.1.12, via swagger-ui), find-my-way (9.10.2), @fastify/swagger, @fastify/swagger-ui and @fastify/cors are all above their patched versions.
  • npm audit on a fresh install reports 0 vulnerabilities.

Testing

  • The response-validation test now asserts that the rejected body is not logged. It previously asserted that it was.
  • New tests cover almost-right tokens (one character short, one extra, different case, a 10 KB token) and the version warning (5.12.5 warns; 5.12.6, 5.13.0-rc.1 and 6.0.0 don't).
  • yarn lint, yarn typecheck, yarn test (201 passed), yarn build and yarn test:dist all pass locally.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Static bearer-token checks now handle mismatched tokens more safely, including very long values.
    • Response validation logs show the validation issues without including the rejected response data.
    • The API server now warns when used with an older Fastify version.
  • Chores
    • Updated the rate-limiting package version.

…ries

- require @fastify/rate-limit ^11.3.0 so ranges can no longer resolve to
  versions affected by GHSA-24mh-2vvh-5r45 (CVE-2026-133312)
- compare static API tokens in constant time
- stop logging the rejected response body when response validation fails,
  as it can contain secrets or personal data
- emit a process warning when a provided Fastify instance is older than
  5.12.6, the first release without known advisories

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The API server now warns when a supplied Fastify instance is older than 5.12.6, compares static bearer tokens using a timing-safe function, and omits rejected response values from validation logs. The package manifest also updates the @fastify/rate-limit dependency range.

Changes: API safeguards

Layer / File(s) Summary
Version and token comparison helpers
src/api-server.ts
The server adds numeric Fastify version comparison that ignores prerelease suffixes. Static tokens are hashed with SHA-256 and compared using timingSafeEqual.
Safeguard wiring and tests
src/api-server.ts, test/unit/api-server.test.ts, test/unit/auth.test.ts
The constructor warns when a supplied Fastify version is below 5.12.6. Static bearer-token validation uses the new token comparison. Tests cover Fastify warning cases and invalid static tokens.
Response validation log content
src/api-server.ts, test/unit/request-handling.test.ts
Validation failures log the validation issues without the handler response value. The test checks that the serialized logs omit the rejected secret.

Rate-limit dependency update

Layer / File(s) Summary
Rate-limit dependency range
package.json
The @fastify/rate-limit dependency range changes from ^11.2.2 to ^11.3.0.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: julusian

Merge Risk: Low · up to b7716

Response validation failures no longer log rejected response values, which was the intent. Property names from rejected responses can still appear in logs, but only in unusual dynamically keyed cases. This can be addressed before or shortly after merge; the rest of the change looks safe to merge.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@willosof
willosof merged commit 8894a70 into main Nov 29, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant