Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2026-03-01 - [OAuth postMessage Origin Hardening]
**Vulnerability:** Insecure use of `postMessage` with wildcard origin (`'*'`) and weak origin validation using `startsWith`.
**Learning:** OAuth redirect handlers often use `window.opener.postMessage` to send authorization codes back to the main application window. Using `'*'` allows any site that can open or reference the redirect window to intercept these codes. Furthermore, using `startsWith` for origin validation is bypassable (e.g., `https://trusted.com.attacker.com` starts with `https://trusted.com`).
**Prevention:** Always use a specific target origin in `postMessage` calls. For origin validation in message listeners, use strict equality with a derived origin from a trusted URL (e.g., `new URL(trustedUrl).origin === event.origin`). Always add safety checks for URL parsing.
2 changes: 1 addition & 1 deletion packages/react-ui/src/app/routes/redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const RedirectPage: React.FC = React.memo(() => {
{
code: code,
},
'*',
window.location.origin,
);
}
}, [location.search]);
Expand Down
14 changes: 11 additions & 3 deletions packages/react-ui/src/lib/oauth2-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@ function constructUrl(params: OAuth2PopupParams, pckeChallenge: string) {
return url.toString();
}

function getCode(redirectUrl: string): Promise<string> {
function getCode(redirectUrl: string | undefined): Promise<string> {
return new Promise<string>((resolve) => {
window.addEventListener('message', function handler(event) {
if (!redirectUrl) {
return;
}
let origin;
try {
origin = new URL(redirectUrl).origin;
} catch (e) {
return;
}
if (
redirectUrl &&
redirectUrl.startsWith(event.origin) &&
origin === event.origin &&
event.data['code']
) {
resolve(decodeURIComponent(event.data.code));
Expand Down
3 changes: 2 additions & 1 deletion packages/server/api/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,13 @@ export const setupApp = async (app: FastifyInstance): Promise<FastifyInstance> =
return reply.send('The code is missing in url')
}
else {
const origin = await domainHelper.getPublicUrl({})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve tenant-specific origin in OAuth redirect

Using domainHelper.getPublicUrl({}) here hard-codes the default frontend URL as the postMessage target, which breaks OAuth callbacks opened from tenant/custom domains. In Enterprise, THIRD_PARTY_AUTH_PROVIDER_REDIRECT_URL is generated per platformId (via getThirdPartyRedirectUrl(platformId)), so the popup can run on a custom domain while this script posts only to the global frontend origin; browsers drop that message and the login flow never resolves.

Useful? React with πŸ‘Β / πŸ‘Ž.

return reply
.type('text/html')
.send(
`<script>if(window.opener){window.opener.postMessage({ 'code': '${encodeURIComponent(
params.code,
)}' },'*')}</script> <html>Redirect succuesfully, this window should close now</html>`,
)}' }, '${origin}')}</script> <html>Redirect succuesfully, this window should close now</html>`,
)
}
},
Expand Down
Loading