fix: recipe config cleanup, report-only CSP, logout redirect validation (#6124)

This commit is contained in:
Alireza authored and GitHub committed 2026-07-07 13:18:46 -04:00
1 parent 973631b7e8
commit f8546ce0e0
27 files changed
+446 -75

No files matched your search

@@ -5,6 +5,7 @@ import CallbackPage from '../routes/CallbackPage';
import SignoutCallbackComponent from '../routes/SignoutCallbackComponent';
import LegacyClient from './legacyOIDCClient';
import NextClient from './nextOIDCClient';
import { sanitizeSameOriginRedirect } from './sanitizeRedirect';
function _isAbsoluteUrl(url) {
return url.includes('http://') || url.includes('https://');
@@ -55,7 +56,10 @@ function LogoutComponent(props) {
const location = useLocation();
const query = new URLSearchParams(location.search);
userManager.signoutRedirect({
post_logout_redirect_uri: query.get('redirect_uri'),
post_logout_redirect_uri: sanitizeSameOriginRedirect(
query.get('redirect_uri'),
window.location.origin
),
});
return null;
}
@@ -0,0 +1,40 @@
import { sanitizeSameOriginRedirect } from './sanitizeRedirect';
describe('sanitizeSameOriginRedirect', () => {
const origin = 'https://viewer.example.com';
it('returns the same href back for an absolute same-origin URL', () => {
expect(sanitizeSameOriginRedirect('https://viewer.example.com/worklist?a=1', origin)).toBe(
'https://viewer.example.com/worklist?a=1'
);
});
it('resolves relative paths against the app origin', () => {
expect(sanitizeSameOriginRedirect('/worklist', origin)).toBe(
'https://viewer.example.com/worklist'
);
});
it('rejects an absolute cross-origin URL', () => {
expect(sanitizeSameOriginRedirect('https://evil.example.com/', origin)).toBeUndefined();
});
it('rejects a protocol-relative cross-origin URL', () => {
expect(sanitizeSameOriginRedirect('//evil.example.com/x', origin)).toBeUndefined();
});
it('rejects javascript: scheme values', () => {
expect(sanitizeSameOriginRedirect('javascript:alert(1)', origin)).toBeUndefined();
});
it('rejects null and empty values', () => {
expect(sanitizeSameOriginRedirect(null, origin)).toBeUndefined();
expect(sanitizeSameOriginRedirect('', origin)).toBeUndefined();
});
it('rejects lookalike hosts that merely start with the app host', () => {
expect(
sanitizeSameOriginRedirect('https://viewer.example.com.evil.com/', origin)
).toBeUndefined();
});
});
@@ -0,0 +1,22 @@
/**
* Returns the given redirect target only when it resolves to the provided
* origin; otherwise returns undefined so callers fall back to the configured
* post-logout destination.
*/
export function sanitizeSameOriginRedirect(
value: string | null,
origin: string
): string | undefined {
if (!value) {
return undefined;
}
try {
const url = new URL(value, origin);
if (url.origin !== origin) {
return undefined;
}
return url.href;
} catch {
return undefined;
}
}