fix: image and URL references refuse a /\ path, which browsers read as another host (WR-20)

safeImageURL and ValidURLRef refused only //, so a stored og_image of
/\evil.example/x.png loaded a third-party image in the admin. Both now
refuse /\ like models.validTarget already does.
This commit is contained in:
2026-10-27 15:38:56 +01:00
parent d8aa989dfc
commit 882d4ee05f
5 changed files with 59 additions and 6 deletions

View File

@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest'
import { safeImageURL } from '../../assets/src/elements/image'
// E7 golem15-seo-image: which stored URLs the preview may load.
describe('E7 safeImageURL', () => {
it('accepts a path and an http(s) URL', () => {
for (const url of ['/media/a.png', 'https://cdn.example/a.png', 'HTTP://cdn.example/a.png']) {
expect(safeImageURL(url), url).toBe(true)
}
})
it('refuses addresses a browser reads as another host or another scheme (WR-20)', () => {
for (const url of ['//evil.example/x.png', '/\\evil.example/x.png', 'javascript:alert(1)', 'data:image/png;base64,AA', 'a.png', '']) {
expect(safeImageURL(url), url).toBe(false)
}
})
})