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

@@ -2,9 +2,13 @@ import { el, emit, labelsFor, uid, uiLocaleOf, type Labels } from './labels'
export const IMAGE_TAG = 'golem15-seo-image'
/** Whether a stored image URL may be shown: a path or an http(s) URL. */
/**
* Whether a stored image URL may be shown: a path or an http(s) URL. A
* path starting with // or /\ is refused: browsers read both as another
* host (like classes.ValidURLRef).
*/
export function safeImageURL(url: string): boolean {
return /^\/(?!\/)/.test(url) || /^https?:\/\//i.test(url)
return /^\/(?![\/\\])/.test(url) || /^https?:\/\//i.test(url)
}
/**