Skip to content

fix(api): add security hardening headers - #12

Closed
thomasorgeval wants to merge 1 commit into
mainfrom
sentinel-security/api-security-headers
Closed

fix(api): add security hardening headers#12
thomasorgeval wants to merge 1 commit into
mainfrom
sentinel-security/api-security-headers

Conversation

@thomasorgeval

Copy link
Copy Markdown
Member

Summary

  • Add a reusable API security headers middleware.
  • Apply no-referrer, nosniff, deny-framing, and restrictive permissions-policy headers to all API responses.
  • Cover the middleware with a focused unit test.

Expected impact

  • Reduces browser-side attack surface for API and upload responses by default.
  • Prevents MIME sniffing, clickjacking via framing, unnecessary referrer leakage, and accidental browser feature access.

Verification

  • NX_DAEMON=false pnpm nx test api --skip-nx-cache
  • NX_DAEMON=false pnpm nx typecheck api --skip-nx-cache
  • pnpm format:check
  • NX_DAEMON=false pnpm nx lint api --skip-nx-cache

@thomasorgeval
thomasorgeval marked this pull request as ready for review June 22, 2026 08:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e30c2e3844

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +12 to +15
context.header(name, value)
}

await next()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply headers after raw responses are finalized

For routes that return a native Response instead of using context.json()/context.body()—notably the Better Auth handler mounted at /api/auth/*—Hono does not merge headers queued before await next() into that returned response unless context.res was already created. As a result, these hardening headers are missing from auth responses even though this middleware is registered globally; set them after await next() or otherwise ensure they are applied to the finalized response.

Useful? React with 👍 / 👎.

@thomasorgeval
thomasorgeval deleted the sentinel-security/api-security-headers branch June 22, 2026 08:29
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