π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
π Security fix for auth headers sent to lookalike origins
Alicia Sykes86c509494303
diff --git a/src/utils/request.js b/src/utils/request.jsindex 8f6bb566..27d7dab7 100644--- a/src/utils/request.js+++ b/src/utils/request.js@@ -16,10 +16,17 @@ import { statusErrorMsg, statusMsg } from '@/utils/logging/CoolConsole';/** Check if a request URL targets the local Dashy server */function isLocalRequest(url) {if (!url) return false;- if (url.startsWith('/') && !url.startsWith('//')) return true;const { origin } = window.location;const domain = import.meta.env.VITE_APP_DOMAIN;- return url.startsWith(origin) || (domain && url.startsWith(domain));+ try {+ const target = new URL(url, origin);+ if (target.origin === origin) return true;+ if (!domain) return false;+ const server = new URL(domain, origin);+ return target.origin === server.origin && target.pathname.startsWith(server.pathname);+ } catch {+ return false;+ }}function hasAuthorization(headers) {diff --git a/tests/unit/request-auth.test.js b/tests/unit/request-auth.test.jsindex baa9b5ce..6abccdb6 100644--- a/tests/unit/request-auth.test.js+++ b/tests/unit/request-auth.test.js@@ -32,12 +32,14 @@ async function loadRequest({describe('request auth headers', () => {beforeEach(() => {+ window.happyDOM.setURL('https://dash.example.com/');vi.restoreAllMocks();localStorage.getItem.mockReset();global.fetch = vi.fn(() => Promise.resolve(new Response('{"ok":true}', { status: 200 })));});afterEach(() => {+ vi.unstubAllEnvs();vi.doUnmock('@/utils/auth/Auth');vi.doUnmock('@/utils/auth/OidcAuth');vi.doUnmock('@/utils/auth/KeycloakAuth');@@ -141,4 +143,42 @@ describe('request auth headers', () => {headers: {},}));});++ it('sends auth to absolute URLs on the same origin', async () => {+ localStorage.getItem.mockReturnValue(null);+ const request = await loadRequest();++ await request.get('https://dash.example.com/conf.yml');++ expect(fetch).toHaveBeenCalledWith('https://dash.example.com/conf.yml', expect.objectContaining({+ headers: { Authorization: 'Basic abc' },+ }));+ });++ it.each([+ 'https://dash.example.com.evil.tld/conf.yml',+ 'https://dash.example.com:8443/conf.yml',+ '/\\evil.tld/conf.yml',+ ])('does not send auth to %s, which is a different origin', async (url) => {+ localStorage.getItem.mockReturnValue(null);+ const request = await loadRequest();++ await request.get(url);++ expect(fetch).toHaveBeenCalledWith(url, expect.objectContaining({ headers: {} }));+ });++ it('matches VITE_APP_DOMAIN by origin, not prefix', async () => {+ vi.stubEnv('VITE_APP_DOMAIN', 'https://api.example.com');+ localStorage.getItem.mockReturnValue(null);+ const request = await loadRequest();++ await request.get('https://api.example.com/status-check');+ await request.get('https://api.example.com.evil.tld/status-check');++ expect(fetch.mock.calls.map(([, options]) => options.headers)).toEqual([+ { Authorization: 'Basic abc' },+ {},+ ]);+ });});