-
Notifications
You must be signed in to change notification settings - Fork 14
Added middleware header #1087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Added middleware header #1087
Changes from all commits
07c8b54
b0f9bd0
f0696a1
20a0e75
fcea591
c34ae93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,14 @@ import { next } from '@vercel/functions'; | |
| import { projectRegex } from './src/shared/projectRegex'; | ||
|
|
||
| const FETCH_TIMEOUT_MS = 2000; | ||
| const DESCOPE_MIDDLEWARE_HEADER = 'x-descope-middleware'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we really need this - it's always false with the x-frame-header and always true otherwise. WDYT? |
||
|
|
||
| const getConfigBaseUrl = (url: URL): string => { | ||
| // When accessing the Vercel deployment directly (e.g. for testing), | ||
| // the .well-known endpoint doesn't exist on the Vercel origin. | ||
| // Fall back to the production API for the configuration check. | ||
|
tomski747 marked this conversation as resolved.
|
||
| if (url.hostname.endsWith('.preview.descope.org')) { | ||
| return 'https://api.descope.com'; | ||
| return 'https://api.descope.org'; | ||
|
tomski747 marked this conversation as resolved.
|
||
| } | ||
|
tomski747 marked this conversation as resolved.
|
||
| return url.origin; | ||
| }; | ||
|
|
@@ -36,7 +37,7 @@ const middleware = async (request: Request) => { | |
| const projectConfig = await response.json(); | ||
| if (projectConfig.allowAuthHostingIframeEmbedding === true) { | ||
| // Project explicitly allows iframe embedding — omit X-Frame-Options | ||
| return next(); | ||
| return next({ headers: { [DESCOPE_MIDDLEWARE_HEADER]: 'true' } }); | ||
|
tomski747 marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } catch { | ||
|
|
@@ -49,6 +50,7 @@ const middleware = async (request: Request) => { | |
| // Default: add X-Frame-Options to prevent clickjacking | ||
| return next({ | ||
| headers: { | ||
| [DESCOPE_MIDDLEWARE_HEADER]: 'false', | ||
| 'X-Frame-Options': 'SAMEORIGIN' | ||
| } | ||
|
Comment on lines
51
to
55
|
||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 HIGH: Tests not updated — all assertions will fail.
The test file
src/middleware.test.tswas not modified in this PR, but every assertion is now stale:"Embedding allowed" path (lines 85, 97): Tests assert
expect(mockedNext).toHaveBeenCalledWith()(zero args), but the code now passesnext({ headers: { 'x-descope-middleware': 'true' } }). These two tests will fail.expectXFrameOptionshelper (lines 22-26): Assertsnext()is called with{ headers: { 'X-Frame-Options': 'SAMEORIGIN' } }, but the code now also includes'x-descope-middleware': 'false'in the headers object.toHaveBeenCalledWithdoes an exact match on the argument shape, so every test using this helper will fail (6+ tests).Preview URL tests (lines 160-162, 175-177): Assert
api.descope.comin the fetch URL, but the code now usesapi.descope.org. Both config-base-URL tests will fail.Please update
src/middleware.test.tsto match the new behavior.