feat(security): add anti-framing headers (X-Frame-Options + CSP frame-ancestors)#430
Merged
wyuc merged 1 commit intoTHU-MAIC:mainfrom Apr 15, 2026
Merged
Conversation
a9a4313 to
99d8478
Compare
…-ancestors) Add X-Frame-Options: SAMEORIGIN and Content-Security-Policy: frame-ancestors 'self' response headers to prevent clickjacking and unauthorized third-party embedding. Closes THU-MAIC#428
99d8478 to
03783b9
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.
Summary
Add
X-Frame-Options: SAMEORIGINandContent-Security-Policy: frame-ancestors 'self'response headers to prevent clickjacking and unauthorized third-party embedding of the application.Supports an optional
ALLOWED_FRAME_ANCESTORSenvironment variable to whitelist trusted origins (e.g., for partner sites that need to embed OpenMAIC).Changes
next.config.tsheaders()function that applies anti-framing headers to all routes via the/(.*)source pattern.X-Frame-Options: SAMEORIGIN— legacy header for older browser compatibility (omitted when custom ancestors are configured, since X-Frame-Options doesn't support allow-lists).Content-Security-Policy: frame-ancestors 'self'— modern standard that restricts which origins can embed this site in an iframe.ALLOWED_FRAME_ANCESTORSenv var to append trusted origins (space-separated).tests/server/security-headers.test.ts(new)headers()is defined in the Next.js config.X-Frame-OptionsandContent-Security-Policy: frame-ancestorsare present with default config.ALLOWED_FRAME_ANCESTORScorrectly appends origins to the CSP directive.X-Frame-Optionsis omitted when custom ancestors are set.Configuration
By default, only same-origin framing is allowed. To whitelist additional origins:
Verification
After deployment, the headers can be verified with:
Closes #428
Closes #429