Keep the CSRF token on same-origin API calls and lint colours in the build (#45)
CI / ci (push) Successful in 1m33s
CI / ci (pull_request) Successful in 1m31s
Independent review Codex gpt-6-sol high: APPROVED (0 findings)

Co-authored-by: dev_agent <dev_agent@cubecraftlabs.com>
Co-committed-by: dev_agent <dev_agent@cubecraftlabs.com>
This commit was merged in pull request #45.
This commit is contained in:
2026-10-04 09:08:42 -04:00
committed by approver_agent
parent 048d5dd71a
commit 5758f198e4
4 changed files with 52 additions and 8 deletions
+24
View File
@@ -34,6 +34,30 @@ describe('apiFetch', () => {
expect(fetchMock).not.toHaveBeenCalled()
})
it.each([
'https://evil.example/api/v1/me',
'//evil.example/api/v1/me',
// The placeholder origin an earlier guard compared against.
'//same-origin.invalid/api/v1/me',
'https://same-origin.invalid/api/v1/me',
'/\\evil.example/api/v1/me',
'/auth/logout',
'/api/v1/../auth/logout',
'/api/v1/%2e%2e/auth/logout',
'api/v1/me',
])('refuses %s without sending it or the CSRF token', async (path) => {
const fetchMock = stubFetch(jsonResponse(200, ME))
const api = createApiClient(fakeLocation())
await api.loadMe()
await expect(api.apiFetch(path, { method: 'POST', body: {} })).rejects.toThrow(
`POST ${path}: not a same-origin /api/v1/ path`,
)
expect(fetchMock).toHaveBeenCalledTimes(1)
expect(request(fetchMock, 0)).toMatchObject({ path: '/api/v1/me', method: 'GET' })
expect(request(fetchMock, 0).headers.has(CSRF_HEADER)).toBe(false)
})
it('rejects with a typed ApiError from the error body', async () => {
stubFetch(errorResponse(503, 'unavailable', true))
const api = createApiClient(fakeLocation())