security: add real security headers middleware#663
Open
mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
Open
security: add real security headers middleware#663mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
Conversation
37d8888 to
e1a585d
Compare
| } | ||
|
|
||
| it('valid key with matching scope — calls next()', async () => { | ||
| const hash = await hashApiKey(TOKEN) |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class
| }) | ||
|
|
||
| const mw = requireApiKey('search:read') | ||
| const result = await mw(ctx, mockNext) |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class
- Create security-headers.ts middleware replacing pass-through stub - Set X-Content-Type-Options: nosniff (prevents MIME sniffing) - Set X-Frame-Options: SAMEORIGIN (blocks external framing) - Set Referrer-Policy: strict-origin-when-cross-origin - Set Permissions-Policy: camera=(), microphone=(), geolocation=() - Set HSTS (1 year) in non-development environments - Apply middleware in app.ts security slot - Replace stub export in middleware/index.ts Fixes VULN-005
e1a585d to
cd18de8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security: Add Real Security Headers Middleware
Summary
Replaces the no-op security headers placeholder with real security headers on every response. Prevents clickjacking, MIME-type sniffing, referrer leakage, and enforces HTTPS in production.
Changes
1. Security Headers Middleware
await next())2. Headers Set
X-Content-Type-OptionsnosniffX-Frame-OptionsSAMEORIGINReferrer-Policystrict-origin-when-cross-originPermissions-Policycamera=(), microphone=(), geolocation=()Strict-Transport-Securitymax-age=31536000; includeSubDomains3. Replaces No-Op Stub
securityHeadersexport inmiddleware/index.tswas a no-op pass-throughsecurityHeadersMiddlewareimplementationapp.tsmounts the real middleware where the empty placeholder wasTechnical Details
New File:
packages/core/src/middleware/security-headers.ts--securityHeadersMiddleware()factory functionUpdated Files:
packages/core/src/middleware/index.ts-- Re-exports real implementation instead of stubpackages/core/src/app.ts-- Imports and mountssecurityHeadersMiddleware()on*(replacing the no-op)Testing
Performance Impact
No measurable impact -- setting 5 response headers adds negligible overhead.
Breaking Changes
X-Frame-Options: SAMEORIGINwill prevent embedding SonicJS admin pages in iframes from other domains. This is intentional.Migration Notes
No action required. Headers are applied automatically on all responses.
Known Issues
None.
Demo / Screenshots
N/A -- no UI changes. Headers visible in browser DevTools Network tab.
Related Issues
(Security hardening -- no linked issue)
Checklist