2FA setup required: review round 2 — no SVG from the icon endpoint, migrations at container start
R2-1: /api/ipal/admin-icon answers with bytes only for a bitmap recognised by its first bytes (PNG, JPEG, GIF, WebP, ICO, AVIF). An SVG favicon keeps the redirect to the media file: a site-wide CSP rule overrides a route's own sandbox header, so the header alone protected nothing in a built site. buildUploadSecurityHeaders also returns a rule for the icon path, as a second layer. R2-2: the SQL migration runs when the new container starts (prodMigrations, or the start command), never in Coolify's pre-deployment command; docs and the log line say so and point to deployment.md 4.3. R2-3: requireSetup: null is the default. R2-4: the missing-column log line only for a column error. R2-5, R2-6: the resetAccess example keeps the code check; with guard: false the reset endpoint does not exist. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
75a6f5209e
commit
01e3813723
@@ -84,18 +84,55 @@ describe('the tab icon endpoint and an SVG', () => {
|
||||
user: null,
|
||||
}
|
||||
|
||||
// A Next project's site-wide CSP rule overrides a route's own header, so the sandbox header alone protects
|
||||
// nothing in a real site: the endpoint must not answer with an SVG at all.
|
||||
test.each([
|
||||
['an SVG', SVG, 'image/svg+xml'],
|
||||
['a PNG', png, 'image/png'],
|
||||
])('%s is served with the sandbox policy and nosniff', async (_name, body, type) => {
|
||||
['an SVG that the media server calls a PNG', SVG, 'image/png'],
|
||||
['an SVG with a byte-order mark and an XML header', `\ufeff<?xml version="1.0"?>${SVG}`, 'image/svg+xml'],
|
||||
['HTML that claims to be an image', '<html><script>1</script></html>', 'image/gif'],
|
||||
])('%s is never answered from here: a redirect to the media file instead', async (_name, body, type) => {
|
||||
vi.stubGlobal('fetch', respond(body, { headers: { 'content-type': type }, status: 200 }))
|
||||
const res = await icon().handler(req as never)
|
||||
expect(res.status).toBe(302)
|
||||
expect(res.headers.get('location')).toBe('https://example.com/api/media/file/icon.svg')
|
||||
expect(res.headers.get('content-type') ?? '').not.toContain('svg')
|
||||
expect(await res.text()).toBe('')
|
||||
})
|
||||
|
||||
test.each([
|
||||
['PNG', Buffer.from('89504e470d0a1a0a0000', 'hex'), 'image/png'],
|
||||
['JPEG', Buffer.from('ffd8ffe000104a46', 'hex'), 'image/jpeg'],
|
||||
['GIF', Buffer.from('GIF89a..'), 'image/gif'],
|
||||
['WebP', Buffer.concat([Buffer.from('RIFF'), Buffer.alloc(4), Buffer.from('WEBPVP8 ')]), 'image/webp'],
|
||||
['ICO', Buffer.from('000001000100', 'hex'), 'image/x-icon'],
|
||||
['AVIF', Buffer.concat([Buffer.alloc(4), Buffer.from('ftypavif')]), 'image/avif'],
|
||||
])('a %s is served, typed by its own bytes, with the sandbox policy and nosniff', async (_name, body, type) => {
|
||||
// the media server's claim is ignored — here it even claims SVG
|
||||
vi.stubGlobal('fetch', respond(body, { headers: { 'content-type': 'image/svg+xml' }, status: 200 }))
|
||||
const res = await icon().handler(req as never)
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.headers.get('content-type')).toBe(type)
|
||||
expect(res.headers.get('content-security-policy')).toBe("default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; sandbox")
|
||||
expect(res.headers.get('x-content-type-options')).toBe('nosniff')
|
||||
})
|
||||
|
||||
test('rasterImageType knows bitmaps only', async () => {
|
||||
const { rasterImageType } = await import('../src/modules/branding/publicImage.js')
|
||||
expect(rasterImageType(Buffer.from(SVG))).toBeNull()
|
||||
expect(rasterImageType(Buffer.from(''))).toBeNull()
|
||||
expect(rasterImageType(Buffer.from('%PDF-1.7'))).toBeNull()
|
||||
expect(rasterImageType(png)).toBe('image/png')
|
||||
})
|
||||
|
||||
test('buildUploadSecurityHeaders also covers the icon path (a second layer; the project lists it after the site-wide rule)', async () => {
|
||||
const { buildUploadSecurityHeaders, UPLOAD_SECURITY_HEADERS } = await import('../src/modules/security/buildSecurityHeaders.js')
|
||||
expect(buildUploadSecurityHeaders().map((r) => r.source)).toEqual(['/api/media/file/:path*', '/api/ipal/admin-icon'])
|
||||
expect(buildUploadSecurityHeaders()[1].headers).toEqual([...UPLOAD_SECURITY_HEADERS])
|
||||
expect(buildUploadSecurityHeaders({ adminIcon: '/cms/ipal/admin-icon', collections: ['media', 'files'] }).map((r) => r.source)).toEqual(['/api/media/file/:path*', '/api/files/file/:path*', '/cms/ipal/admin-icon'])
|
||||
expect(buildUploadSecurityHeaders({ adminIcon: false }).map((r) => r.source)).toEqual(['/api/media/file/:path*'])
|
||||
})
|
||||
|
||||
test('the headers are the ones of the upload routes', async () => {
|
||||
const { buildUploadSecurityHeaders, UPLOAD_SECURITY_HEADERS } = await import('../src/modules/security/buildSecurityHeaders.js')
|
||||
expect(buildUploadSecurityHeaders()[0].headers).toEqual([...UPLOAD_SECURITY_HEADERS])
|
||||
@@ -103,7 +140,7 @@ describe('the tab icon endpoint and an SVG', () => {
|
||||
})
|
||||
|
||||
test('adminMeta.serveIcon: false → the redirect to the media file, no fetch', async () => {
|
||||
const fetchMock = respond(SVG, { headers: { 'content-type': 'image/svg+xml' }, status: 200 })
|
||||
const fetchMock = respond(png, { headers: { 'content-type': 'image/png' }, status: 200 })
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const res = await icon({ serveIcon: false }).handler(req as never)
|
||||
expect(res.status).toBe(302)
|
||||
|
||||
Reference in New Issue
Block a user