Sign-in look: the logo check never follows a redirect; the review pictures stay out of the package

checkLogoFile asks only the address the upload has (redirect: 'manual'); a redirecting logo counts as
unknown, so the server fetches nothing at an internal address. docs/dev/login-page/*.png is excluded
in package.json files (npm pack --dry-run: none of them packed).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 21:44:39 +01:00
co-authored by Claude Fable 5.2
parent 939ab679c7
commit 562bf5388d
4 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ client's sign-in page (the credit line under the form is separate: `credit: fals
the sign-in screens until it uploads a bitmap or sets the option).
- **Looked at before it is printed:** the server fetches the file as an anonymous visitor would (at most 512 KB)
and reads its first bytes. A deleted, broken, renamed, non-image or too large file gives the site's name, never
a broken picture. The answer is remembered for ten minutes. When nothing answers at all (a container that cannot
a broken picture. A redirect is never followed by the server. The answer is remembered for ten minutes. When nothing answers at all (a container that cannot
reach its own public address), the upload document is believed. `checkLogo: false` turns the look off.
- **Size:** fits 240 × 72 px (192 × 56 on a phone), never enlarged or cropped, `width` and `height` set (no
layout shift). Served from the smallest generated size (`imageSizes` of the media collection) that is at least
+1
View File
@@ -102,6 +102,7 @@
"files": [
"dist",
"docs",
"!docs/dev/login-page/*.png",
"bin",
"src/modules/block-library"
],
+5 -1
View File
@@ -132,6 +132,9 @@ export type LogoCheck = 'bad' | 'unknown' | { bytes: Buffer; type: string }
* - `'bad'` when the server ANSWERS and it is no such picture: 404, another type, too large, broken bytes;
* - `'unknown'` when nothing answers (the site cannot reach its own address from inside its container, a
* timeout): the upload document is then believed, so a network quirk never takes the logo away.
* A redirect is NEVER followed: the server asks only the address the upload itself has, so a logo address
* that answers "go to http://169.254.169.254/…" (or any internal host) makes the server fetch nothing there.
* Such a logo counts as `'unknown'`: the browser may follow it, the server does not.
*/
export async function checkLogoFile(url: string, base: null | string | undefined, allowSvg = false): Promise<LogoCheck> {
let target: URL
@@ -143,11 +146,12 @@ export async function checkLogoFile(url: string, base: null | string | undefined
if (target.protocol !== 'http:' && target.protocol !== 'https:') {return 'bad'}
let res: Response
try {
res = await fetch(target, { credentials: 'omit', redirect: 'follow', signal: AbortSignal.timeout(4000) })
res = await fetch(target, { credentials: 'omit', redirect: 'manual', signal: AbortSignal.timeout(4000) })
} catch {
return 'unknown'
}
try {
if ((res.status >= 300 && res.status < 400) || res.type === 'opaqueredirect') {return 'unknown'}
if (!res.ok) {return res.status >= 500 ? 'unknown' : 'bad'}
const declared = Number(res.headers.get('content-length'))
if (Number.isFinite(declared) && declared > PUBLIC_IMAGE_MAX_BYTES) {return 'bad'}
+9
View File
@@ -225,6 +225,15 @@ describe('what the public sign-in page may show', () => {
serve(PNG, { headers: { 'content-length': String(600 * 1024), 'content-type': 'image/png' } })
expect((await brand()).logo).toBeNull()
vi.restoreAllMocks()
// a redirect is never followed by the server (it could point at an internal address): one request, to the
// logo's own address, asked not to follow; the upload document is believed and nothing is inlined from it
const redirected = serve(null, { headers: { location: 'http://169.254.169.254/latest/meta-data/' }, status: 302 })
expect((await brand()).logo?.src).toBe(settings.logo.url)
expect(redirected).toHaveBeenCalledTimes(1)
expect(String(redirected.mock.calls[0][0])).toBe('https://site.test/api/media/file/logo.png')
expect((redirected.mock.calls[0][1] as RequestInit).redirect).toBe('manual')
expect(await checkLogoFile('https://site.test/l.png', null)).toBe('unknown')
vi.restoreAllMocks()
// nothing answers (the site cannot reach its own address): the upload document is believed
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('ECONNREFUSED'))
expect((await brand()).logo?.src).toBe(settings.logo.url)