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:
co-authored by
Claude Fable 5.2
parent
939ab679c7
commit
562bf5388d
+1
-1
@@ -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).
|
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)
|
- **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
|
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.
|
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
|
- **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
|
layout shift). Served from the smallest generated size (`imageSizes` of the media collection) that is at least
|
||||||
|
|||||||
@@ -102,6 +102,7 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"docs",
|
"docs",
|
||||||
|
"!docs/dev/login-page/*.png",
|
||||||
"bin",
|
"bin",
|
||||||
"src/modules/block-library"
|
"src/modules/block-library"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -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;
|
* - `'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
|
* - `'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.
|
* 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> {
|
export async function checkLogoFile(url: string, base: null | string | undefined, allowSvg = false): Promise<LogoCheck> {
|
||||||
let target: URL
|
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'}
|
if (target.protocol !== 'http:' && target.protocol !== 'https:') {return 'bad'}
|
||||||
let res: Response
|
let res: Response
|
||||||
try {
|
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 {
|
} catch {
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if ((res.status >= 300 && res.status < 400) || res.type === 'opaqueredirect') {return 'unknown'}
|
||||||
if (!res.ok) {return res.status >= 500 ? 'unknown' : 'bad'}
|
if (!res.ok) {return res.status >= 500 ? 'unknown' : 'bad'}
|
||||||
const declared = Number(res.headers.get('content-length'))
|
const declared = Number(res.headers.get('content-length'))
|
||||||
if (Number.isFinite(declared) && declared > PUBLIC_IMAGE_MAX_BYTES) {return 'bad'}
|
if (Number.isFinite(declared) && declared > PUBLIC_IMAGE_MAX_BYTES) {return 'bad'}
|
||||||
|
|||||||
@@ -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' } })
|
serve(PNG, { headers: { 'content-length': String(600 * 1024), 'content-type': 'image/png' } })
|
||||||
expect((await brand()).logo).toBeNull()
|
expect((await brand()).logo).toBeNull()
|
||||||
vi.restoreAllMocks()
|
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
|
// nothing answers (the site cannot reach its own address): the upload document is believed
|
||||||
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('ECONNREFUSED'))
|
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('ECONNREFUSED'))
|
||||||
expect((await brand()).logo?.src).toBe(settings.logo.url)
|
expect((await brand()).logo?.src).toBe(settings.logo.url)
|
||||||
|
|||||||
Reference in New Issue
Block a user