Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Copy link
Copy Markdown

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.ts was not modified in this PR, but every assertion is now stale:

  1. "Embedding allowed" path (lines 85, 97): Tests assert expect(mockedNext).toHaveBeenCalledWith() (zero args), but the code now passes next({ headers: { 'x-descope-middleware': 'true' } }). These two tests will fail.

  2. expectXFrameOptions helper (lines 22-26): Asserts next() is called with { headers: { 'X-Frame-Options': 'SAMEORIGIN' } }, but the code now also includes 'x-descope-middleware': 'false' in the headers object. toHaveBeenCalledWith does an exact match on the argument shape, so every test using this helper will fail (6+ tests).

  3. Preview URL tests (lines 160-162, 175-177): Assert api.descope.com in the fetch URL, but the code now uses api.descope.org. Both config-base-URL tests will fail.

Please update src/middleware.test.ts to match the new behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.
Comment thread
tomski747 marked this conversation as resolved.
if (url.hostname.endsWith('.preview.descope.org')) {
return 'https://api.descope.com';
return 'https://api.descope.org';
Comment thread
tomski747 marked this conversation as resolved.
}
Comment thread
tomski747 marked this conversation as resolved.
return url.origin;
};
Expand Down Expand Up @@ -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' } });
Comment thread
tomski747 marked this conversation as resolved.
}
}
} catch {
Expand All @@ -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

Copilot AI Feb 24, 2026

Copy link

Choose a reason for hiding this comment

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

Default response headers now include x-descope-middleware: false in addition to X-Frame-Options. Update existing assertions that expect only X-Frame-Options (e.g., the expectXFrameOptions() helper in src/middleware.test.ts) so they account for the additional header.

Copilot uses AI. Check for mistakes.
});
Expand Down
Loading