From aef1efac7322423d2dc61f1256cc1def60fd7e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Thu, 26 Nov 2026 22:03:52 +0100 Subject: [PATCH] Public brand image fetch: the site's configured origin only, no redirect followed, a time and a byte limit /api/ipal/admin-og resolved a relative logo address against the request's own host and fetched it with Node's defaults (redirects followed, no timeout, no size cap); /api/ipal/admin-icon resolved the same way. Both now resolve against serverURL / NEXT_PUBLIC_SERVER_URL (never the request) and fetch through fetchPublicImage, which asks one address with redirect: 'manual' (a 3xx is no image), within PUBLIC_IMAGE_TIMEOUT_MS, reading at most 512 KB. The renderer still draws PNG, JPEG, GIF (by their bytes) and SVG (by its type, as before). Tests against local servers: hostile Host / X-Forwarded-Host, a 302 to an internal host, an endless body, a hanging server, the normal logo. Docs say 1.17.1 instead of 1.18.0. Co-Authored-By: Claude Fable 5.2 --- .../skills/iapl-reference/resources/api.md | 2 +- docs/agent/skills/iapl-upgrade/SKILL.md | 2 +- docs/dev/login-page/changelog-draft.md | 14 +- docs/white-label.md | 6 + .../skills/iapl-reference/resources/api.md | 2 +- .../.agents/skills/iapl-upgrade/SKILL.md | 2 +- src/index.ts | 2 +- src/modules/branding/adminImages.tsx | 46 +++-- src/modules/branding/publicImage.ts | 23 ++- src/types.ts | 2 +- test/adminMeta.test.ts | 9 +- test/brandImageFetch.test.ts | 159 ++++++++++++++++++ test/publicImage.test.ts | 4 +- 13 files changed, 244 insertions(+), 29 deletions(-) create mode 100644 test/brandImageFetch.test.ts diff --git a/docs/agent/skills/iapl-reference/resources/api.md b/docs/agent/skills/iapl-reference/resources/api.md index 3423cc6..a65c6e1 100644 --- a/docs/agent/skills/iapl-reference/resources/api.md +++ b/docs/agent/skills/iapl-reference/resources/api.md @@ -624,7 +624,7 @@ Server only (`pnpm payload run`); never import it from client code, the Payload | `buildTwoFactorResetEndpoint(collection, { access? })`, `TWO_FACTOR_RESET_PATH` | `@intecion/ipal-kit` | `POST /api/ipal/two-factor/reset` `{ userId }`: clears the account's TOTP secret and sessions and starts a new window. Default: a staff admin whose session entered its own TOTP code; `access` replaces that (only `true` allows; a session that owes its code is always refused). `iapl` registers it only with `twoFactor.guard` on. | | `countAccountsWithoutTotp(payload, collection, setupWindowMs?)` | `@intecion/ipal-kit` | `{ without, blocked }` — accounts of the 2FA collection without TOTP, and how many are past their window. | | `resolveRequireSetup(option)`, `strictExempt(fn)`, `SETUP_FROM_FIELD`, `DEFAULT_SETUP_WINDOW_HOURS` | `@intecion/ipal-kit` | `twoFactor.requireSetup` → `{ requireSetup, setupWindowMs, exempt? }` as the guard reads it (throws on a `windowHours` that is not a number ≥ 0 or `false`, and on an `async` `exempt`); the wrapper that makes an `exempt` function answer `true` only for exactly `true`; the field name `'totpSetupFrom'`; `72`. | -| `fetchPublicImage(url, base)`, `publicImageDataUri(url, base)`, `rasterImageType(bytes)`, `siteOrigin(serverURL)`, `PUBLIC_IMAGE_MAX_BYTES` | `@intecion/ipal-kit` | An image fetched the way an anonymous visitor gets it (no cookies; http(s) only; `image/*`; at most 512 KB, reading stops at the limit) as `{ bytes, type }` or a `data:` address, else `null`. Used for the logo and icon on the 2FA screens. `rasterImageType(bytes)` → the media type of a bitmap by its first bytes (PNG, JPEG, GIF, WebP, ICO, AVIF) or `null` — never trust a claimed type before answering a file's bytes from the site's origin; an SVG gives `null`. | +| `fetchPublicImage(url, base, { timeoutMs? }?)`, `publicImageDataUri(url, base)`, `rasterImageType(bytes)`, `siteOrigin(serverURL)`, `PUBLIC_IMAGE_MAX_BYTES`, `PUBLIC_IMAGE_TIMEOUT_MS` | `@intecion/ipal-kit` | An image fetched the way an anonymous visitor gets it, as `{ bytes, type }` or a `data:` address, else `null`: no cookies; http(s) only; `image/*`; ONE address — a redirect is never followed (a 3xx is "no image"); the whole exchange within `PUBLIC_IMAGE_TIMEOUT_MS` (5000); at most `PUBLIC_IMAGE_MAX_BYTES` (512 KB), reading stops at the limit whatever `content-length` says. `base` is the site's configured origin (`siteOrigin(config.serverURL)` = `serverURL`, else `NEXT_PUBLIC_SERVER_URL`) — never build it from a request's `Host` / `X-Forwarded-Host`. Used for the logo and icon on the 2FA screens and by `/api/ipal/admin-og` and `/api/ipal/admin-icon`. `rasterImageType`: the bitmap type by the first bytes (PNG, JPEG, GIF, WebP, ICO, AVIF), `null` for anything else, SVG included. | | `resolveSignInLook(whiteLabel)` | `@intecion/ipal-kit` | `whiteLabel` option → `null` (white-label or `signIn` off) or `{ allScreens, props }` (`ResolvedSignInLook`; `props` = `SignInLookProps`, the plain values the components get: `accent`, `checkLogo`, `imageField`, `inlineImages`, `languages`, `logoPlate`, `nameField`, `settingsSlug`, `svgLogo`). Option type: `SignInLookOptions`. | | `loadSignInBrand({ payload, look, locale?, user? })`, `signInName(value, locale?)`, `signInLogo(media, { svgLogo? })`, `checkLogoFile(url, base, allowSvg?)`, `fitLogo(width, height, box?)`, `isSvgUpload(media)`, `SIGN_IN_LOGO_TYPES` | `@intecion/ipal-kit` | What the sign-in panel shows: `{ name, logo }` (`SignInBrand`, `SignInLogo = { src, width?, height? }`) read from Site settings, never throwing; the name as one line of plain text (control characters out, cut at `SIGN_IN_NAME_MAX` = 80); the logo of an upload document — only JPEG / PNG / WebP / AVIF / GIF (`SIGN_IN_LOGO_TYPES`; SVG with `svgLogo: true`), only an `http(s)` or site-relative address, fitted into `SIGN_IN_LOGO_BOX` (240 × 72) without enlarging, served from the smallest generated size ≥ 2× the shown width with the same proportions; the look at the file itself (`LogoCheck`: `{ bytes, type }`, `'bad'` = the server answered and it is no such picture or over 512 KB, `'unknown'` = nothing answered). A session that owes its 2FA code gets the checked picture inlined or no logo. | | `signInCss({ accent? })`, `isHexColour(value)`, `SIGN_IN_STYLE_ID` | `@intecion/ipal-kit` | The stylesheet of the sign-in look as a string (no `url()`, no font, no other host; every rule needs `.iapl-signin` on the page), the hex check `accent` must pass, and the `href` of its `