Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(js): guard protocol-relative URLs in shouldRedirectToLoginOn401 (follow-up to #4940) (#4944)

LearningCircuitde3f6a7c3c61
diff --git a/src/local_deep_research/web/static/js/services/api.js b/src/local_deep_research/web/static/js/services/api.js
index 7356929a75..35a6da5ff6 100644
--- a/src/local_deep_research/web/static/js/services/api.js
+++ b/src/local_deep_research/web/static/js/services/api.js
@@ -42,7 +42,12 @@ function getApiUrl(path) {
*/
function shouldRedirectToLoginOn401(url) {
if (typeof window === 'undefined') return false;
- if (!url.startsWith('/')) return false; // external URL
+ if (!url.startsWith('/')) return false; // external (absolute) URL
+ // Reject cross-origin bypass forms: //host is protocol-relative, and a
+ // backslash is normalized to '/' by browsers, so both //host and /\host
+ // resolve cross-origin (verified via URL()). Mirrors the server's
+ // is_safe_redirect_url, which rejects a leading // and any backslash.
+ if (url.startsWith('//') || url.includes('\\')) return false;
if (window.location.pathname.startsWith('/auth/')) return false; // already in login flow
if (url.startsWith('/auth/')) return false; // auth handles its own 401s
return true;
diff --git a/tests/js/services/api.test.js b/tests/js/services/api.test.js
index c3faaec6ea..909c178700 100644
--- a/tests/js/services/api.test.js
+++ b/tests/js/services/api.test.js
@@ -34,6 +34,15 @@ describe('shouldRedirectToLoginOn401', () => {
expect(shouldRedirectToLoginOn401('https://api.example.com/foo')).toBe(false);
});
+ it('does not redirect for a protocol-relative (cross-origin) URL', () => {
+ expect(shouldRedirectToLoginOn401('//api.example.com/foo')).toBe(false);
+ });
+
+ it('does not redirect for a backslash-bypass URL that resolves cross-origin', () => {
+ // `/\evil.com` is normalized by browsers to https://evil.com (cross-origin)
+ expect(shouldRedirectToLoginOn401('/\\evil.com')).toBe(false);
+ });
+
it('does not redirect for a request to /auth/*', () => {
expect(shouldRedirectToLoginOn401('/auth/check')).toBe(false);
});