Sign-in look: the logo follows IAWL's rules; no plate by default; the brand fields are admin-only

Bitmaps only (JPEG, PNG, WebP, AVIF, GIF; SVG with svgLogo: true), the file fetched and checked by its
bytes before it is printed (checkLogo; 512 KB; ten-minute memory; an unreachable address is believed),
served from a generated size at least twice the shown width. logoPlate replaces logoMadeFor: no plate
unless asked. With the look on, the name, logo and icon of Site settings are changed by admins only
(brandAccess: 'editor' gives them back). Docs, skills, changelog draft, tests and pictures follow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 20:52:41 +01:00
co-authored by Claude Fable 5.2
parent 3ceeab8469
commit 939ab679c7
67 changed files with 343 additions and 111 deletions
+1 -1
View File
@@ -1171,7 +1171,7 @@ project → **plugin gap**, not a copy.
| Mail | `email: mailAdapter()` + `serverURL` — mail works with no other setup, through the Intecion mail service; SMTP in the panel only when the client asks; your own mail: `payload.sendEmail` (`withMailKind` when it is account mail); never a second transport in the project. §7.2 | email.md |
| Env validation, health | `assertEnv(iaplEnvRules({…}))` (`/env`), `healthRoute` | env.md |
| 2FA, white-label, headers | `twoFactor: { issuer, plugin: payloadTotp }`, `whiteLabel`, `buildSecurityHeaders` | security.md, white-label.md |
| Sign-in screens (login, forgot / reset password, first user, logout, the 2FA screens): a dark panel with the client's logo or the site's name beside the form, language links, both themes, phone | on with `whiteLabel` (`signIn`); a NEW site: `whiteLabel: { signIn: { allScreens: true } }` + `pnpm payload generate:importmap` (adds the provider `SignInLook`; without it only login and the 2FA screens get the look, through `AdminLogo` / `SafeTotpView`). Logo and name come from Site settings (no env var, no new field, no migration). Options: `accent` (hex), `logoMadeFor: 'dark'`, `languages: false`, `svgLogo: false`; `signIn: false` = Payload's screens; `brandAccess: 'admin'` = only admins change name / logo / icon. Never build a login page, a custom `graphics.Logo` or login CSS by hand. Check: `curl -s $URL/admin/login \| grep -c iapl-signin__label` ≥ 1; `curl -si "$URL/api/ipal/admin-language?lng=xx"` → 400 | white-label.md → "The sign-in screens" |
| Sign-in screens (login, forgot / reset password, first user, logout, the 2FA screens): a dark panel with the client's logo or the site's name beside the form, language links, both themes, phone | on with `whiteLabel` (`signIn`); a NEW site: `whiteLabel: { signIn: { allScreens: true } }` + `pnpm payload generate:importmap` (adds the provider `SignInLook`; without it only login and the 2FA screens get the look, through `AdminLogo` / `SafeTotpView`). Logo and name come from Site settings (no env var, no new field, no migration). The logo is a bitmap (JPEG, PNG, WebP, AVIF, GIF; an SVG logo shows the name unless `svgLogo: true`), checked by its bytes before it is printed (`checkLogo`), without a plate (`logoPlate: true` for a logo with dark letters). Options: `accent` (hex), `languages: false`; `signIn: false` = Payload's screens. Name / logo / icon are admin-only with the look (`brandAccess: 'editor'` = as before). Never build a login page, a custom `graphics.Logo` or login CSS by hand. Check: `curl -s $URL/admin/login \| grep -c iapl-signin__label` ≥ 1; `curl -si "$URL/api/ipal/admin-language?lng=xx"` → 400 | white-label.md → "The sign-in screens" |
| Panel link preview + noindex (site name, description, preview image, technology support credit) | on by default (`adminMeta`, `agency`) — do not hand-write `admin.meta` for it; override single keys in `admin.meta` or `adminMeta: { … }` | white-label.md |
| Rate limit (forms, MCP, search) | built in; IP from `IAPL_IP_HEADER`; several instances → `setRateLimitStore` | forms.md |
+5 -4
View File
@@ -64,13 +64,14 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
| `whiteLabel.logoField` / `iconField` / `nameField` | `'logo'` / `'favicon'` / `'siteName'` | fields in Site settings | any upload/text field |
| `whiteLabel.titleSuffix` | none | `admin.meta.titleSuffix` (tab title) | — |
| `whiteLabel.credit` | on | `IntecionCredit` in `afterLogin` and `afterNavLinks`: "Technology support: Intecion.com" (en/pl, from `agency`) | `false`; `{ text, url }` overrides |
| `whiteLabel.signIn` | on (with `whiteLabel`) | the sign-in look: a dark panel with the client's logo (Site settings → Logo, on a white plate) or the site's name beside the form, "Administration panel", language links; both themes, a band above the form on a phone. Login, the 2FA screens and e-mail verification get it through `AdminLogo` / `SafeTotpView` (already in the import map: an upgrade needs no edit). No env var, no new field, no migration | `false` = Payload's own screens |
| `whiteLabel.signIn` | on (with `whiteLabel`) | the sign-in look: a dark panel with the client's logo (Site settings → Logo: JPEG / PNG / WebP / AVIF / GIF, fetched and checked by its bytes before it is printed, ≤ 512 KB, fits 240 × 72, no plate) or the site's name beside the form, "Administration panel", language links; both themes, a band above the form on a phone. Login, the 2FA screens and e-mail verification get it through `AdminLogo` / `SafeTotpView` (already in the import map: an upgrade needs no edit). No env var, no new field, no migration | `false` = Payload's own screens |
| `whiteLabel.signIn.allScreens` | `false` (the starter writes `true`) | the look on forgot / reset password, create first user, logout and "unauthorized" too: adds the provider `SignInLook` — ONE new import-map entry, run `pnpm payload generate:importmap`. Production start: when `importMap.js` on disk lacks it, the provider is left out and the log says `[iapl] The sign-in look covers only the login and 2FA screens …` | `true` |
| `whiteLabel.signIn.accent` | `#0070c0` | hex colour of the button, links and focus ring (anything that is not a hex colour is ignored); or CSS variables `--iapl-signin-*` on `:root` in the admin's `custom.scss` | `'#0b6e4f'` |
| `whiteLabel.signIn.logoMadeFor` | `'light'` | `'dark'` = a logo drawn for dark grounds: no white plate | — |
| `whiteLabel.signIn.logoPlate` | `false` (the logo straight on the dark panel: upload one that works on dark) | `true` = a white plate behind the logo (dark letters) | — |
| `whiteLabel.signIn.checkLogo` | on | the logo's file is fetched as an anonymous visitor gets it and its first bytes read (10-minute memory); a deleted / broken / non-image / > 512 KB file → the site's name; nothing answers → the upload document is believed | `false` = no fetch |
| `whiteLabel.signIn.languages` | shown with 2+ admin languages | links on the panel; `GET /api/ipal/admin-language?lng=<code>` writes Payload's `payload-lng` cookie and redirects (303) back to the admin path of the `Referer`; unknown language → 400 | `false` = no links, no endpoint |
| `whiteLabel.signIn.svgLogo` | shown as a picture (`<img>` runs no script) | `false` = an SVG logo is not shown on the sign-in screens; the site's name is | — |
| `whiteLabel.brandAccess` | `'editor'` (whoever edits Site settings) | `'admin'` = field-level `access.update` on the name, logo and icon fields: only admins change what the sign-in screens show. No schema change | — |
| `whiteLabel.signIn.svgLogo` | `false`: an SVG logo is NOT shown on the sign-in screens (the site's name is) — tell the client to upload a PNG / WebP logo | `true` = shown as a picture (`<img>` runs no script) | — |
| `whiteLabel.brandAccess` | `'admin'` with the sign-in look (else `'editor'`) | field-level `access.update` on the name, logo and icon fields of Site settings: only admins change what the sign-in screens show; editors keep the rest. No schema change | `'editor'` = whoever edits Site settings |
| `agency` | `{ name: 'Intecion.com', url: 'https://intecion.com' }` | the credit line, the panel's link description and preview image | `{ name, url }` = another agency; `false` = none anywhere |
| `adminMeta` | on (with or without `whiteLabel`) | panel `<head>`: `robots` noindex/nofollow, `titleSuffix` "— <site> \| Panel", `og:site_name` + description from Site settings (refreshed on save), `og:image` `GET /api/ipal/admin-og` (1200×630 from the logo or name), icon `GET /api/ipal/admin-icon` (favicon or initials); no import map step | `false` = Payload defaults; `{ robots, titleSuffix, description, image, icons, language }` (each `false` or your value; `{site}`, `{agency}` placeholders); your own `admin.meta` keys always win. Check: `curl -s $URL/admin/login \| grep -E 'og:\|robots'` (white-label.md) |
| `pages` | none | Site settings → **System pages** (page roles) and **Maintenance** tabs | omit → neither tab |
@@ -625,8 +625,8 @@ Server only (`pnpm payload run`); never import it from client code, the Payload
| `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`. |
| `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`, `imageField`, `inlineImages`, `languages`, `logoMadeFor`, `nameField`, `settingsSlug`, `svgLogo`). Option type: `SignInLookOptions`. |
| `loadSignInBrand({ payload, look, locale?, user? })`, `signInName(value, locale?)`, `signInLogo(media, { svgLogo? })`, `fitLogo(width, height, box?)`, `isSvgUpload(media)` | `@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 an `http(s)` or site-relative address; `null` for SVG with `svgLogo: false`), fitted into `SIGN_IN_LOGO_BOX` (240 × 72) without enlarging. A session that owes its 2FA code gets the picture inlined (`publicImageDataUri`) or no logo. |
| `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 `<style>` (`'iapl-sign-in'`). |
| `languageLinks(config, current)`, `LANGUAGE_NAMES`, `buildAdminLanguageEndpoint()`, `adminPathFromReferer(referer, adminRoute)`, `ADMIN_LANGUAGE_PATH` | `@intecion/ipal-kit` | The panel's languages as links (`LanguageLink[]`: `{ code, name, current, href }`; empty with one language; names in their own language, else the code); the public endpoint `GET /api/ipal/admin-language?lng=` (`'/ipal/admin-language'`) that writes `<cookiePrefix>-lng` for a supported language (else 400) and answers 303 to a path inside the admin route taken from the `Referer` (anything else → the admin root, never another host). |
| `signInProviderActive(payload)`, `SIGN_IN_LOOK` | `@intecion/ipal-kit` | Whether the provider `'@intecion/ipal-kit/admin#SignInLook'` is in the config AND in the running import map — `AdminLogo` and `SafeTotpView` print the panel themselves only when it is not. |
+4 -2
View File
@@ -297,8 +297,10 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo
- Sign-in screens (`whiteLabel.signIn`, on): a dark panel with the client's logo or the site's name beside the
form; the logo and name are Site settings fields (no env var, no migration). `allScreens: true` (in the config
above) adds the provider `SignInLook` to the import map and covers forgot / reset password, first user and
logout. `accent: '#hex'`, `logoMadeFor: 'dark'` (a white logo), `languages: false`, `svgLogo: false`;
`signIn: false` = Payload's screens; `brandAccess: 'admin'` = only admins change name, logo and icon.
logout. The logo: JPEG / PNG / WebP / AVIF / GIF (an SVG logo shows the name: `svgLogo: true` or upload a
bitmap), drawn for a DARK ground (no plate; `logoPlate: true` for a logo with dark letters). `accent: '#hex'`,
`languages: false`, `checkLogo: false`; `signIn: false` = Payload's screens. Name, logo and icon in Site
settings are admin-only with the look (`brandAccess: 'editor'` gives them back to editors).
Check: `/admin/login` and `/admin/forgot` show the panel, also at a phone width; do not write login CSS by hand.
- Panel link preview (`adminMeta`, on): noindex/nofollow, "— <site> | Panel" suffix, site name, description and
preview image (`/api/ipal/admin-og`) from Site settings; `agency` names who supports the technology (default
+6 -1
View File
@@ -653,7 +653,12 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re
look — a dark panel with the client's logo or the site's name beside the form. No edit, no
`generate:importmap`, no migration: the look comes through `AdminLogo` and `SafeTotpView`, which the site's
import map already has. **Check:** open `/admin/login` on a desktop and at a phone width, in both themes; sign
in through 2FA. A logo that looks wrong on the white plate (a white logo): `signIn: { logoMadeFor: 'dark' }`.
in through 2FA.
**Look at the logo:** it stands straight on a dark panel. A logo with dark letters: `signIn: { logoPlate: true }`
(a white plate) or ask the client for a logo for dark grounds. An **SVG** logo is not shown there (the site's
name is): upload a PNG / WebP logo, or `signIn: { svgLogo: true }`.
**Editors lose three fields:** the name, logo and icon of Site settings are admin-only now (they are what the
public sign-in page shows). A site whose editors must change them: `whiteLabel: { brandAccess: 'editor' }`.
2. **Tell the owner the sign-in page looks different** and ask whether to keep it. No: `whiteLabel: { signIn: false }`
— Payload's screens with the plain logo, as before (record it in AGENTS.md → Project decisions).
3. **Recommended, one edit:** `whiteLabel: { signIn: { allScreens: true } }`, `pnpm payload generate:importmap`,
+9 -5
View File
@@ -13,10 +13,11 @@ site; `after-*` from a production build with `signIn: { allScreens: true }`, `be
|---|---|
| `before-*.png` | IAPL 1.17.0: login (light, dark, phone, Polish, wrong password), forgot password, 2FA code, 2FA setup; `-logo` = with a logo set |
| `after-*-name.png` | the new look with no logo set: the site's name |
| `after-*-logo.png` | the new look with a logo (`placeholder-logo.png`, drawn for these pictures) |
| `after-*-logo.png` | the new look with a logo made for dark grounds (`placeholder-logo-for-dark.png`), no plate — the default |
| `after-login-*-logo-dark-letters-no-plate.png` | a logo with dark letters (`placeholder-logo.png`) on the default: hard to read; such a site sets `logoPlate: true` |
| `after-first-user-*.png` | create first user on an empty database (no site name yet: the host is shown) |
| `legacy-unedited-*.png` | the reference site as it was at v1.16.7, **unedited**, built against this plugin: login has the look (through `AdminLogo`), forgot password and create first user are Payload's own until the project sets `allScreens` |
| `iawl-*.png` | IAWL's sign-in page, copied from its repository (`docs/reviews/white-label/`, made 2026-11-24). Two later changes are not in them: the languages are plain links now (no drop-down with a button), and messages are square boxes with a straight bar |
| `iawl-*.png` | IAWL's sign-in page, copied from its repository (`docs/reviews/white-label/`, made 2026-11-24; the languages are still a drop-down there). `iawl-current-sign-in.png` is the page as built now (`docs/reviews/rule-13/after-5-sign-in.png`) |
| `placeholder-logo*.png` | the placeholder logos (dark text; white text for `logoMadeFor: 'dark'`) |
Screens: `login-{light,dark,phone,phone-dark,pl}`, `login-error-{light,phone}`, `forgot-{light,dark,phone}`,
@@ -48,7 +49,9 @@ without users: `--only=first-user`). The files are 8-bit PNGs (re-encoded to kee
| Element | IAPL | Same as IAWL? |
|---|---|---|
| Split, panel inset and corners, grid, glows, colours | the same numbers (`css.ts`) | yes |
| Label, plate, logo box, name as text, link to the site | the same | yes |
| Label, logo box (240 × 72, 2× source), name as text, link to the site, alternative text | the same | yes |
| Logo types (JPEG, PNG, WebP, AVIF, GIF; no SVG) and the look at the file before printing | the same; Payload accepts SVG uploads, so `svgLogo: true` exists; the file is checked by a fetch (IAWL reads the disk), and an unreachable address counts as "believe the upload" | yes, two notes |
| Plate | **no plate by default** (the owner's choice for new surfaces), `logoPlate: true` adds it | IAWL: plate by default, `logoMadeFor => 'dark'` removes it |
| Button, link, focus and border colours; field and button heights; 28 rem column | the same | yes |
| Phone band at 52 rem | the same | yes |
| Languages | links, **on the panel** (top corner; under the brand on a phone), because the form's markup is Payload's and differs per screen | place differs |
@@ -67,8 +70,9 @@ without users: `--only=first-user`). The files are 8-bit PNGs (re-encoded to kee
2. **The panel is one self-contained element**, fixed on a desktop and in the flow on a phone, hidden by its own
CSS off the minimal template. It therefore works wherever it is printed (inside the login form's wrapper, before
a 2FA view, at the top of the body).
3. **No new stored data.** Logo and name are Site settings fields that exist since 1.0: no migration. The plate
switch (`logoMadeFor`) and the accent are code options; putting them in the panel would add columns on SQL.
3. **No new stored data.** Logo and name are Site settings fields that exist since 1.0 — the ones the public site
reads — so every part of the site shows the same logo and there is no migration. The plate switch (`logoPlate`)
and the accent are code options; putting them in the panel would add columns on SQL.
4. **Payload draws its admin screens in the browser** (the server's HTML body is empty until React runs), so "no
flash" means: the panel, its stylesheet and the form appear in the same step. The e2e spec checks that the
form's template is never in the page without them.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

+18 -8
View File
@@ -9,28 +9,38 @@ the 2FA screens (code, setup) show a dark panel with the client's logo — or th
look IAPL now shares with IAWL. No edit, no `generate:importmap`, no migration, no new env var.
Keep Payload's screens: `whiteLabel: { signIn: false }`. Sites without `whiteLabel`: nothing changes.
Three things to look at on such a site, each with a one-line way back:
- **The logo stands straight on a dark panel** (no plate). A logo with dark letters: `signIn: { logoPlate: true }`.
- **An SVG logo is not shown on the sign-in screens** (the site's name is; the rest of the site is untouched):
upload a PNG / WebP logo or set `signIn: { svgLogo: true }`.
- **Editors can no longer change the site's name, logo and icon** in Site settings (admins can): these are what the
public sign-in page shows. `whiteLabel: { brandAccess: 'editor' }` gives them back.
## Added
- **Sign-in look (`whiteLabel.signIn`, on with `whiteLabel`).** A dark panel with the label "Administration panel",
the client's logo on a white plate (Site settings → Logo) or the site's name, and the panel's languages as links;
the client's logo (Site settings → Logo) or the site's name, and the panel's languages as links;
the form beside it, in both admin themes; a band above the form on a phone. Logo and name come from Site settings:
no env var, **no new field, no schema change** (MongoDB, Postgres, SQLite alike). With nothing set the panel shows
the label and the site's host — no Payload or Intecion mark.
the label and the site's host — no Payload or Intecion mark. The logo on a white plate is an option; the default is no plate.
- **`signIn: { allScreens: true }`** — the same look on forgot / reset password, create first user, logout and
"unauthorized". Adds the provider `SignInLook` (one import-map entry: `pnpm payload generate:importmap`). The
project starter writes it for new sites. A production start that does not find the entry in `importMap.js`
leaves the provider out and logs what to run; the panel keeps working.
- **Options:** `signIn.accent` (hex colour of the button, links and focus ring), `signIn.logoMadeFor: 'dark'` (a
white logo: no plate), `signIn.languages: false`, `signIn.svgLogo: false` (an SVG logo is not shown on the sign-in
screens), `whiteLabel.brandAccess: 'admin'` (only admins change the name, logo and icon in Site settings;
field-level access, no schema change). CSS variables `--iapl-signin-*` for a project's `custom.scss`.
- **The logo follows IAWL's rules:** JPEG, PNG, WebP, AVIF or GIF; fetched and checked by its bytes before it is
printed (at most 512 KB; a deleted or broken file gives the name); fits 240 × 72, served from a generated size
at least twice as wide when the media collection has one; alternative text = the site's name.
- **Options:** `signIn.accent` (hex colour of the button, links and focus ring), `signIn.logoPlate` (a white plate),
`signIn.svgLogo` (allow an SVG logo), `signIn.checkLogo: false`, `signIn.languages: false`,
`whiteLabel.brandAccess` (`'admin'` with the look, `'editor'` as before; field-level access, no schema change).
CSS variables `--iapl-signin-*` for a project's `custom.scss`.
- **Language links before sign-in:** `GET /api/ipal/admin-language?lng=<code>` writes Payload's language cookie for
a supported language and returns to the admin page it was opened from (public; 400 for an unknown language;
never redirects off the admin route). Registered only with the sign-in look and `languages !== false`.
- **The 2FA code boxes have names** for screen readers ("Digit 2 of 6") and ask a phone for the numeric keyboard
(with the sign-in look).
- Exports: `SignInPanel`, `SignInLook` (`/admin`); `resolveSignInLook`, `loadSignInBrand`, `signInLogo`,
`signInName`, `fitLogo`, `isSvgUpload`, `languageLinks`, `LANGUAGE_NAMES`, `signInCss`, `isHexColour`,
`signInName`, `checkLogoFile`, `fitLogo`, `isSvgUpload`, `SIGN_IN_LOGO_TYPES`, `languageLinks`, `LANGUAGE_NAMES`, `signInCss`, `isHexColour`,
`signInProviderActive`, `buildAdminLanguageEndpoint`, `adminPathFromReferer`, `SIGN_IN_LOOK`, `SIGN_IN_STYLE_ID`,
`SIGN_IN_LOGO_BOX`, `SIGN_IN_NAME_MAX`, `ADMIN_LANGUAGE_PATH` and their types.
@@ -44,5 +54,5 @@ Keep Payload's screens: `whiteLabel: { signIn: false }`. Sites without `whiteLab
## Requires project changes
None. Recommended: `allScreens` (one config line, regenerate the import map). A project with its own CSS for the
None for the panel to work — but read the three points at the top. Recommended: `allScreens` (one config line, regenerate the import map). A project with its own CSS for the
login screen looks at the result after the update.
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

+32 -17
View File
@@ -45,8 +45,8 @@ whiteLabel: {
| `iconField` | `'favicon'` | `graphics.Icon` → `AdminIcon` (max 28×28 px) |
| `titleSuffix` | none (`adminMeta` builds one from the site name) | static `admin.meta.titleSuffix`, wins over `adminMeta` |
| `credit` | `true` | `false` or `{ text?, url? }` |
| `signIn` | `true` | the look of the sign-in screens (below); `false` = Payload's own screens; `{ allScreens, accent, logoMadeFor, languages, svgLogo }` |
| `brandAccess` | `'editor'` | who may change the name, logo and icon fields: `'admin'` = admins only (field-level access, no schema change) |
| `signIn` | `true` | the look of the sign-in screens (below); `false` = Payload's own screens; `{ allScreens, accent, logoPlate, languages, svgLogo, checkLogo }` |
| `brandAccess` | `'admin'` with the sign-in look | who may change the name, logo and icon fields of Site settings: admins only (field-level access, no schema change); `'editor'` = whoever edits Site settings, as before |
The plugin overrides `admin.components.graphics.Logo` / `Icon` from the project config (its
values win over yours); `afterLogin` / `afterNavLinks` are appended.
@@ -129,10 +129,24 @@ uses too.** No new field, collection or global — so **no migration on Postgres
With nothing set, the panel shows the label and the site's host: no Intecion and no Payload mark is put on a
client's sign-in page (the credit line under the form is separate: `credit: false`).
**The logo.** Shown inside 240 × 72 px (192 × 56 on a phone), never enlarged or cropped, with its `width` and
`height` set (no layout shift). It stands **on a white plate**, so any ordinary logo works on the dark panel; a
logo drawn for dark grounds (a white logo) sets `signIn: { logoMadeFor: 'dark' }` and the plate is left out.
Recommended upload: PNG or WebP, 480 px wide or more, without empty margins.
**The logo — the same rules as on the WordPress sibling (IAWL):**
- **Types:** JPEG, PNG, WebP, AVIF, GIF. **No SVG** (`svgLogo: true` allows it; IAWL has no such switch because
WordPress refuses the upload — Payload accepts SVG uploads, so a site whose logo is an SVG shows its **name** on
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
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
twice the shown width and has the same proportions; else the upload itself. Recommended: PNG or WebP, 480 px
wide or more, without empty margins.
- **Ground: no plate by default** — the logo stands straight on the dark panel, so Site settings should hold a
logo that works on a dark ground (the owner's choice for new surfaces). A logo drawn for light grounds (dark
letters) sets `signIn: { logoPlate: true }` and gets a white plate. *IAWL differs here today:* its default is the
plate, with `logoMadeFor => 'dark'` to leave it out.
- **Text and link:** the alternative text is the site's name; logo and name link to the site's home page.
### Which screens
@@ -161,9 +175,10 @@ screens … Run "pnpm payload generate:importmap"`. Without `allScreens` the oth
| `false` | — | Payload's own sign-in screens; `AdminLogo` is the plain logo, as before |
| `allScreens` | `false` | the look on every sign-in screen (above) |
| `accent` | the shared blue `#0070c0` | a hex colour for the button, the links and the focus ring; it carries white text, so check its contrast (4.5:1) |
| `logoMadeFor` | `'light'` | `'dark'`: no white plate behind the logo |
| `logoPlate` | `false` | `true`: a white plate behind the logo (a logo with dark letters) |
| `languages` | shown when the panel has 2+ languages | `false`: no language links, and no `/api/ipal/admin-language` endpoint |
| `svgLogo` | shown (as a picture) | `false`: an SVG logo is not shown on the sign-in screens; the site's name is |
| `svgLogo` | `false` | `true`: an SVG logo is shown too (as a picture, where it cannot run script) |
| `checkLogo` | `true` | `false`: the logo's file is not fetched and looked at before it is printed |
**Language links.** Plain links, no script: `GET /api/ipal/admin-language?lng=pl` writes Payload's own language
cookie (`payload-lng`, one year) and sends the browser back to the admin page it came from. Public, because nobody
@@ -177,14 +192,14 @@ The sign-in page is open to anyone, so what reaches it is narrow on purpose:
- **Text:** the site's name only, as plain text (escaped; one line, at most 80 characters). No description, no
rich text, no link an editor can write: the panel's only links are the site's own root and the language links.
- **Pictures:** the logo as an `<img>` — a picture in `<img>` never runs script, an SVG included. `svgLogo: false`
leaves SVG out anyway. Only an `http(s)` or site-relative address is used. The plugin serves **no new file** for
it: the logo is the media file at its own address, with the media collection's own headers and cache rules. On
the 2FA screens (the session is refused `media`) the server fetches it as an anonymous visitor would — images
only, at most 512 KB — and inlines it; when that fails the name is shown (`inlineImages`, above).
- **Who can change it:** whoever may edit Site settings — editors and admins by default, as for the public site's
name and logo. `whiteLabel: { brandAccess: 'admin' }` makes the three brand fields (name, logo, icon)
admin-only with field-level access; other Site settings stay with editors.
- **Pictures:** the logo as an `<img>`, bitmaps only (above), checked by its bytes, at most 512 KB; only an
`http(s)` or site-relative address is used. The plugin serves **no new file** for it: the logo is the media file
at its own address, with the media collection's own headers and cache rules. On the 2FA screens (the session is
refused `media`) the picture that was just checked is put into the page as a `data:` image; when it could not
be fetched the name is shown (`inlineImages`, above).
- **Who can change it: admins.** With the sign-in look on, the three brand fields of Site settings (name, logo,
icon) get field-level access for admins only; an editor still edits every other Site setting and sees these
three read-only. No schema change. `whiteLabel: { brandAccess: 'editor' }` gives them back to editors.
- **Accounts:** the forms, their messages and their limits are Payload's and the 2FA package's own, untouched.
The look adds no text that depends on an account, so nothing new says whether an account exists.
- **The stylesheet** is inline, has no `url()`, no font file and no request to another host; `accent` is accepted
@@ -221,7 +236,7 @@ Set the custom properties on `:root` in the admin's `custom.scss` (the defaults
- **Your own panel:** `SignInPanel` (the panel with its stylesheet) and `SignInLook` (the provider) are exported
from `@intecion/ipal-kit/admin`; wire them in `admin.components` with `serverProps: { look: { … } }`
(`SignInLookProps`). From the main entry: `resolveSignInLook`, `loadSignInBrand`, `signInLogo`, `signInName`,
`fitLogo`, `isSvgUpload`, `languageLinks`, `LANGUAGE_NAMES`, `signInCss`, `isHexColour`, `signInProviderActive`,
`checkLogoFile` (`LogoCheck`), `SIGN_IN_LOGO_TYPES`, `fitLogo`, `isSvgUpload`, `languageLinks`, `LANGUAGE_NAMES`, `signInCss`, `isHexColour`, `signInProviderActive`,
`buildAdminLanguageEndpoint`, `adminPathFromReferer`, and the constants `SIGN_IN_LOOK`, `SIGN_IN_STYLE_ID`,
`SIGN_IN_LOGO_BOX`, `SIGN_IN_NAME_MAX`, `ADMIN_LANGUAGE_PATH`; types `SignInLookOptions`, `ResolvedSignInLook`,
`SignInLookProps`, `SignInBrand`, `SignInLogo`, `LanguageLink`, `SignInPanelProps`, `SignInLookProviderProps`.
@@ -64,13 +64,14 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia
| `whiteLabel.logoField` / `iconField` / `nameField` | `'logo'` / `'favicon'` / `'siteName'` | fields in Site settings | any upload/text field |
| `whiteLabel.titleSuffix` | none | `admin.meta.titleSuffix` (tab title) | — |
| `whiteLabel.credit` | on | `IntecionCredit` in `afterLogin` and `afterNavLinks`: "Technology support: Intecion.com" (en/pl, from `agency`) | `false`; `{ text, url }` overrides |
| `whiteLabel.signIn` | on (with `whiteLabel`) | the sign-in look: a dark panel with the client's logo (Site settings → Logo, on a white plate) or the site's name beside the form, "Administration panel", language links; both themes, a band above the form on a phone. Login, the 2FA screens and e-mail verification get it through `AdminLogo` / `SafeTotpView` (already in the import map: an upgrade needs no edit). No env var, no new field, no migration | `false` = Payload's own screens |
| `whiteLabel.signIn` | on (with `whiteLabel`) | the sign-in look: a dark panel with the client's logo (Site settings → Logo: JPEG / PNG / WebP / AVIF / GIF, fetched and checked by its bytes before it is printed, ≤ 512 KB, fits 240 × 72, no plate) or the site's name beside the form, "Administration panel", language links; both themes, a band above the form on a phone. Login, the 2FA screens and e-mail verification get it through `AdminLogo` / `SafeTotpView` (already in the import map: an upgrade needs no edit). No env var, no new field, no migration | `false` = Payload's own screens |
| `whiteLabel.signIn.allScreens` | `false` (the starter writes `true`) | the look on forgot / reset password, create first user, logout and "unauthorized" too: adds the provider `SignInLook` — ONE new import-map entry, run `pnpm payload generate:importmap`. Production start: when `importMap.js` on disk lacks it, the provider is left out and the log says `[iapl] The sign-in look covers only the login and 2FA screens …` | `true` |
| `whiteLabel.signIn.accent` | `#0070c0` | hex colour of the button, links and focus ring (anything that is not a hex colour is ignored); or CSS variables `--iapl-signin-*` on `:root` in the admin's `custom.scss` | `'#0b6e4f'` |
| `whiteLabel.signIn.logoMadeFor` | `'light'` | `'dark'` = a logo drawn for dark grounds: no white plate | — |
| `whiteLabel.signIn.logoPlate` | `false` (the logo straight on the dark panel: upload one that works on dark) | `true` = a white plate behind the logo (dark letters) | — |
| `whiteLabel.signIn.checkLogo` | on | the logo's file is fetched as an anonymous visitor gets it and its first bytes read (10-minute memory); a deleted / broken / non-image / > 512 KB file → the site's name; nothing answers → the upload document is believed | `false` = no fetch |
| `whiteLabel.signIn.languages` | shown with 2+ admin languages | links on the panel; `GET /api/ipal/admin-language?lng=<code>` writes Payload's `payload-lng` cookie and redirects (303) back to the admin path of the `Referer`; unknown language → 400 | `false` = no links, no endpoint |
| `whiteLabel.signIn.svgLogo` | shown as a picture (`<img>` runs no script) | `false` = an SVG logo is not shown on the sign-in screens; the site's name is | — |
| `whiteLabel.brandAccess` | `'editor'` (whoever edits Site settings) | `'admin'` = field-level `access.update` on the name, logo and icon fields: only admins change what the sign-in screens show. No schema change | — |
| `whiteLabel.signIn.svgLogo` | `false`: an SVG logo is NOT shown on the sign-in screens (the site's name is) — tell the client to upload a PNG / WebP logo | `true` = shown as a picture (`<img>` runs no script) | — |
| `whiteLabel.brandAccess` | `'admin'` with the sign-in look (else `'editor'`) | field-level `access.update` on the name, logo and icon fields of Site settings: only admins change what the sign-in screens show; editors keep the rest. No schema change | `'editor'` = whoever edits Site settings |
| `agency` | `{ name: 'Intecion.com', url: 'https://intecion.com' }` | the credit line, the panel's link description and preview image | `{ name, url }` = another agency; `false` = none anywhere |
| `adminMeta` | on (with or without `whiteLabel`) | panel `<head>`: `robots` noindex/nofollow, `titleSuffix` "— <site> \| Panel", `og:site_name` + description from Site settings (refreshed on save), `og:image` `GET /api/ipal/admin-og` (1200×630 from the logo or name), icon `GET /api/ipal/admin-icon` (favicon or initials); no import map step | `false` = Payload defaults; `{ robots, titleSuffix, description, image, icons, language }` (each `false` or your value; `{site}`, `{agency}` placeholders); your own `admin.meta` keys always win. Check: `curl -s $URL/admin/login \| grep -E 'og:\|robots'` (white-label.md) |
| `pages` | none | Site settings → **System pages** (page roles) and **Maintenance** tabs | omit → neither tab |
@@ -625,8 +625,8 @@ Server only (`pnpm payload run`); never import it from client code, the Payload
| `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`. |
| `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`, `imageField`, `inlineImages`, `languages`, `logoMadeFor`, `nameField`, `settingsSlug`, `svgLogo`). Option type: `SignInLookOptions`. |
| `loadSignInBrand({ payload, look, locale?, user? })`, `signInName(value, locale?)`, `signInLogo(media, { svgLogo? })`, `fitLogo(width, height, box?)`, `isSvgUpload(media)` | `@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 an `http(s)` or site-relative address; `null` for SVG with `svgLogo: false`), fitted into `SIGN_IN_LOGO_BOX` (240 × 72) without enlarging. A session that owes its 2FA code gets the picture inlined (`publicImageDataUri`) or no logo. |
| `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 `<style>` (`'iapl-sign-in'`). |
| `languageLinks(config, current)`, `LANGUAGE_NAMES`, `buildAdminLanguageEndpoint()`, `adminPathFromReferer(referer, adminRoute)`, `ADMIN_LANGUAGE_PATH` | `@intecion/ipal-kit` | The panel's languages as links (`LanguageLink[]`: `{ code, name, current, href }`; empty with one language; names in their own language, else the code); the public endpoint `GET /api/ipal/admin-language?lng=` (`'/ipal/admin-language'`) that writes `<cookiePrefix>-lng` for a supported language (else 400) and answers 303 to a path inside the admin route taken from the `Referer` (anything else → the admin root, never another host). |
| `signInProviderActive(payload)`, `SIGN_IN_LOOK` | `@intecion/ipal-kit` | Whether the provider `'@intecion/ipal-kit/admin#SignInLook'` is in the config AND in the running import map — `AdminLogo` and `SafeTotpView` print the panel themselves only when it is not. |
+4 -2
View File
@@ -297,8 +297,10 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo
- Sign-in screens (`whiteLabel.signIn`, on): a dark panel with the client's logo or the site's name beside the
form; the logo and name are Site settings fields (no env var, no migration). `allScreens: true` (in the config
above) adds the provider `SignInLook` to the import map and covers forgot / reset password, first user and
logout. `accent: '#hex'`, `logoMadeFor: 'dark'` (a white logo), `languages: false`, `svgLogo: false`;
`signIn: false` = Payload's screens; `brandAccess: 'admin'` = only admins change name, logo and icon.
logout. The logo: JPEG / PNG / WebP / AVIF / GIF (an SVG logo shows the name: `svgLogo: true` or upload a
bitmap), drawn for a DARK ground (no plate; `logoPlate: true` for a logo with dark letters). `accent: '#hex'`,
`languages: false`, `checkLogo: false`; `signIn: false` = Payload's screens. Name, logo and icon in Site
settings are admin-only with the look (`brandAccess: 'editor'` gives them back to editors).
Check: `/admin/login` and `/admin/forgot` show the panel, also at a phone width; do not write login CSS by hand.
- Panel link preview (`adminMeta`, on): noindex/nofollow, "— <site> | Panel" suffix, site name, description and
preview image (`/api/ipal/admin-og`) from Site settings; `agency` names who supports the technology (default
@@ -653,7 +653,12 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re
look — a dark panel with the client's logo or the site's name beside the form. No edit, no
`generate:importmap`, no migration: the look comes through `AdminLogo` and `SafeTotpView`, which the site's
import map already has. **Check:** open `/admin/login` on a desktop and at a phone width, in both themes; sign
in through 2FA. A logo that looks wrong on the white plate (a white logo): `signIn: { logoMadeFor: 'dark' }`.
in through 2FA.
**Look at the logo:** it stands straight on a dark panel. A logo with dark letters: `signIn: { logoPlate: true }`
(a white plate) or ask the client for a logo for dark grounds. An **SVG** logo is not shown there (the site's
name is): upload a PNG / WebP logo, or `signIn: { svgLogo: true }`.
**Editors lose three fields:** the name, logo and icon of Site settings are admin-only now (they are what the
public sign-in page shows). A site whose editors must change them: `whiteLabel: { brandAccess: 'editor' }`.
2. **Tell the owner the sign-in page looks different** and ask whether to keep it. No: `whiteLabel: { signIn: false }`
— Payload's screens with the plain logo, as before (record it in AGENTS.md → Project decisions).
3. **Recommended, one edit:** `whiteLabel: { signIn: { allScreens: true } }`, `pnpm payload generate:importmap`,
+3 -1
View File
@@ -74,6 +74,7 @@ export {
ADMIN_LANGUAGE_PATH,
adminPathFromReferer,
buildAdminLanguageEndpoint,
checkLogoFile,
fitLogo,
isHexColour,
isSvgUpload,
@@ -81,6 +82,7 @@ export {
languageLinks,
loadSignInBrand,
SIGN_IN_LOGO_BOX,
SIGN_IN_LOGO_TYPES,
SIGN_IN_LOOK,
SIGN_IN_NAME_MAX,
SIGN_IN_STYLE_ID,
@@ -89,7 +91,7 @@ export {
signInName,
signInProviderActive,
} from './modules/branding/signIn/index.js'
export type { LanguageLink, SignInBrand, SignInLogo, SignInLookProps } from './modules/branding/signIn/index.js'
export type { LanguageLink, LogoCheck, SignInBrand, SignInLogo, SignInLookProps } from './modules/branding/signIn/index.js'
export { resolveSignInLook } from './modules/branding/signIn/options.js'
export type { ResolvedSignInLook, SignInLookOptions } from './modules/branding/signIn/options.js'
export {
+2 -2
View File
@@ -21,7 +21,7 @@ export type SignInPanelProps = {
/**
* The dark panel of the sign-in screens with its stylesheet: the label "Administration panel", the client's
* logo (on a white plate unless it was made for dark grounds) or the site's name, and the panel's languages
* logo (straight on the panel; on a white plate with `logoPlate`) or the site's name, and the panel's languages
* as links. A Server Component; it reads Site settings with the `payload` Payload hands it and never throws.
*
* The stylesheet hides it wherever the page is not one of Payload's minimal screens, so the same element can
@@ -33,7 +33,7 @@ export async function SignInPanel(props: SignInPanelProps = {}): Promise<React.R
const text = (key: 'signInLanguage' | 'signInPanelLabel') => (i18n ? iaplT(i18n.t, key) : settingsTexts.en[key])
const brand = await loadSignInBrand({ locale: props.locale, look, payload, user: props.user })
const languages = look.languages === false ? [] : languageLinks(payload?.config, i18n?.language)
const plate = brand.logo && look.logoMadeFor !== 'dark'
const plate = brand.logo && look.logoPlate === true
return (
<>
+114 -19
View File
@@ -3,7 +3,7 @@ import type { Payload } from 'payload'
import { getFromImportMap } from 'payload/shared'
import { secondFactorPassed } from '../../security/totp/secondFactor.js'
import { publicImageDataUri, siteOrigin } from '../publicImage.js'
import { PUBLIC_IMAGE_MAX_BYTES, rasterImageType, siteOrigin } from '../publicImage.js'
/**
* What the sign-in panel shows, read from Site settings: the client's logo or, without one, the site's name.
@@ -12,8 +12,9 @@ import { publicImageDataUri, siteOrigin } from '../publicImage.js'
* What may reach a page that anyone can open, before signing in:
* - the name as plain text (React escapes it), one line of at most `SIGN_IN_NAME_MAX` characters: no markup,
* no link, nothing an address inside it could turn into;
* - the logo as an `<img>`: a picture never runs script there, an SVG included. `svgLogo: false` leaves SVG
* out all the same (the name is shown);
* - the logo as an `<img>`, and only a bitmap: JPEG, PNG, WebP, AVIF or GIF, as the upload says AND as the
* file's first bytes say (the file is looked at before it is printed; a deleted, broken or renamed file
* gives the name, never a broken picture). No SVG unless the project asks (`svgLogo: true`);
* - no account, no e-mail address, no hint whether an account exists: the forms are Payload's own.
*/
@@ -30,26 +31,33 @@ export const SIGN_IN_NAME_MAX = 80
export type SignInLookProps = {
/** Hex colour of the button, the links and the focus ring. */
accent?: string
/** `false`: the logo's file is not fetched and looked at before it is printed. */
checkLogo?: false
/** Upload field of the logo. Default `'logo'`. */
imageField?: string
/** `whiteLabel.inlineImages: false`: never fetch the logo on the server for the 2FA screens. */
inlineImages?: false
/** `false`: no language links on the panel. */
languages?: false
/** `'dark'`: the logo was drawn for dark grounds, so it gets no white plate. */
logoMadeFor?: 'dark' | 'light'
/** `true`: the logo stands on a white plate (a logo drawn for light grounds). Default: no plate. */
logoPlate?: true
/** Field of the site's name. Default `'siteName'`. */
nameField?: string
/** Slug of the settings global. Default `'site-settings'`. */
settingsSlug?: string
/** `false`: an SVG logo is not shown on the sign-in screens (the name is). */
svgLogo?: false
/** `true`: an SVG logo is shown too (as a picture). Default: bitmaps only, an SVG logo gives the name. */
svgLogo?: true
}
export type SignInLogo = { height?: number; src: string; width?: number }
export type SignInBrand = { logo: null | SignInLogo; name: string }
type MediaLike = { filename?: unknown; height?: unknown; mimeType?: unknown; url?: unknown; width?: unknown }
type MediaLike = { filename?: unknown; height?: unknown; mimeType?: unknown; sizes?: unknown; url?: unknown; width?: unknown }
/** The picture types a logo may have on the sign-in screens: the bitmaps a browser shows. */
export const SIGN_IN_LOGO_TYPES = ['image/jpeg', 'image/png', 'image/webp', 'image/avif', 'image/gif'] as const
const usableAddress = (url: unknown): url is string => typeof url === 'string' && /^(?:https?:\/\/|\/(?!\/))/i.test(url.trim())
/** A localized text field may arrive as a string or a { locale: value } map. */
function pickText(value: unknown, locale: string | undefined): string {
@@ -82,17 +90,98 @@ export function fitLogo(width: unknown, height: unknown, box: { height: number;
return { height: Math.max(1, Math.round(height * scale)), width: Math.max(1, Math.round(width * scale)) }
}
/** The logo of an upload document, or null when there is nothing to show. */
/**
* The address to serve for a logo shown `shownWidth` wide: the smallest generated size (the upload's
* `sizes`) that is at least twice that width, has the picture's own proportions (a cropped size is another
* picture) and an allowed type; else the upload itself.
*/
function servedAddress(m: MediaLike, shownWidth: number): string {
const full = (m.url as string).trim()
if (typeof m.width !== 'number' || typeof m.height !== 'number' || !m.sizes || typeof m.sizes !== 'object') {return full}
let best: { url: string; width: number } | null = null
for (const size of Object.values(m.sizes as Record<string, MediaLike | null>)) {
if (!size || typeof size.width !== 'number' || typeof size.height !== 'number' || !usableAddress(size.url)) {continue}
if (size.width < 2 * shownWidth || size.width >= m.width || size.height < 1) {continue}
if (Math.abs(size.width / size.height - m.width / m.height) > 0.02) {continue}
if (typeof size.mimeType === 'string' && !(SIGN_IN_LOGO_TYPES as readonly string[]).includes(size.mimeType.toLowerCase())) {continue}
if (!best || size.width < best.width) {best = { url: size.url.trim(), width: size.width }}
}
return best?.url ?? full
}
/**
* The logo of an upload document, or null when there is nothing to show: no address, an address that is not
* http(s) or site-relative, or a type that is not one of `SIGN_IN_LOGO_TYPES` (SVG only with `svgLogo: true`).
*/
export function signInLogo(media: unknown, look: Pick<SignInLookProps, 'svgLogo'> = {}): null | SignInLogo {
if (!media || typeof media !== 'object') {return null}
const m = media as MediaLike
if (typeof m.url !== 'string' || !m.url.trim()) {return null}
// An address a browser would not load as a picture of the site: only http(s) and site-relative ones.
if (!/^(?:https?:\/\/|\/(?!\/))/i.test(m.url.trim())) {return null}
if (look.svgLogo === false && isSvgUpload(m)) {return null}
return { src: m.url.trim(), ...(fitLogo(m.width, m.height) ?? {}) }
if (!usableAddress(m.url)) {return null}
if (isSvgUpload(m)) {return look.svgLogo === true ? { src: m.url.trim(), ...(fitLogo(m.width, m.height) ?? {}) } : null}
if (typeof m.mimeType !== 'string' || !(SIGN_IN_LOGO_TYPES as readonly string[]).includes(m.mimeType.toLowerCase())) {return null}
const fit = fitLogo(m.width, m.height)
return { src: fit ? servedAddress(m, fit.width) : m.url.trim(), ...(fit ?? {}) }
}
export type LogoCheck = 'bad' | 'unknown' | { bytes: Buffer; type: string }
/**
* Looks at the logo's file the way an anonymous visitor gets it (no cookies, at most 512 KB):
* - the picture itself when it answers and its first bytes are one of the allowed bitmaps (an SVG, allowed
* by `svgLogo: true`, is taken by its `image/svg+xml` type);
* - `'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.
*/
export async function checkLogoFile(url: string, base: null | string | undefined, allowSvg = false): Promise<LogoCheck> {
let target: URL
try {
target = new URL(url, base || undefined)
} catch {
return 'unknown' // a site-relative address and no origin to resolve it against
}
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) })
} catch {
return 'unknown'
}
try {
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'}
const bytes = Buffer.from(await res.arrayBuffer())
if (!bytes.length || bytes.length > PUBLIC_IMAGE_MAX_BYTES) {return 'bad'}
const declaredType = (res.headers.get('content-type') ?? '').split(';')[0].trim().toLowerCase()
if (allowSvg && declaredType === 'image/svg+xml') {return { type: declaredType, bytes }}
const type = rasterImageType(bytes)
return type && (SIGN_IN_LOGO_TYPES as readonly string[]).includes(type) ? { type, bytes } : 'bad'
} catch {
return 'unknown'
} finally {
await res.body?.cancel().catch(() => undefined)
}
}
/** What the last look at a logo's file said, kept for ten minutes per address: one fetch, not one per page view. */
const CHECKED = new Map<string, { at: number; result: LogoCheck }>()
const CHECK_TTL_MS = 10 * 60_000
async function checkedLogo(url: string, base: null | string | undefined, allowSvg: boolean): Promise<LogoCheck> {
const key = `${base ?? ''}|${url}|${allowSvg ? 1 : 0}`
const hit = CHECKED.get(key)
if (hit && Date.now() - hit.at < CHECK_TTL_MS) {return hit.result}
const result = await checkLogoFile(url, base, allowSvg)
if (CHECKED.size > 50) {CHECKED.clear()}
// "nothing answered" is asked again soon; an answer is kept
CHECKED.set(key, { at: result === 'unknown' ? Date.now() - CHECK_TTL_MS + 30_000 : Date.now(), result })
return result
}
/** For tests: forget what was checked. */
export const forgetCheckedLogos = (): void => CHECKED.clear()
/** The host of the site, shown when Site settings has no name. */
function siteHost(serverURL: null | string | undefined): string {
try {
@@ -124,11 +213,17 @@ export async function loadSignInBrand({ locale, look, payload, user }: LoadArgs)
const name = signInName(settings[look.nameField ?? 'siteName'], code) || siteHost(origin)
let logo = signInLogo(settings[look.imageField ?? 'logo'], look)
// A session that still owes its 2FA code (or has not set 2FA up) is refused `media` like every other
// collection: give it the picture itself, fetched as an anonymous visitor would get it. When that fails,
// the name is shown instead of a broken picture.
if (logo && user && !secondFactorPassed({ payload, user })) {
const data = look.inlineImages === false ? null : await publicImageDataUri(logo.src, origin)
logo = data ? { ...logo, src: data } : null
// collection: it gets the picture itself (the one just looked at), or the name.
const pending = Boolean(user && !secondFactorPassed({ payload, user }))
if (logo && (look.checkLogo !== false || pending) && !(pending && look.inlineImages === false)) {
const checked = await checkedLogo(logo.src, origin, look.svgLogo === true)
if (checked === 'bad') {
logo = null
} else if (pending) {
logo = checked === 'unknown' ? null : { ...logo, src: `data:${checked.type};base64,${checked.bytes.toString('base64')}` }
}
} else if (logo && pending) {
logo = null
}
return { name, logo }
} catch (error) {
+3 -1
View File
@@ -1,17 +1,19 @@
export {
ADMIN_LANGUAGE_PATH,
checkLogoFile,
fitLogo,
isSvgUpload,
LANGUAGE_NAMES,
languageLinks,
loadSignInBrand,
SIGN_IN_LOGO_BOX,
SIGN_IN_LOGO_TYPES,
SIGN_IN_LOOK,
SIGN_IN_NAME_MAX,
signInLogo,
signInName,
signInProviderActive,
} from './brand.js'
export type { LanguageLink, SignInBrand, SignInLogo, SignInLookProps } from './brand.js'
export type { LanguageLink, LogoCheck, SignInBrand, SignInLogo, SignInLookProps } from './brand.js'
export { isHexColour, SIGN_IN_STYLE_ID, signInCss } from './css.js'
export { adminPathFromReferer, buildAdminLanguageEndpoint } from './languageEndpoint.js'
+18 -6
View File
@@ -16,12 +16,23 @@ export type SignInLookOptions = {
* without touching its import map; the project starter turns it on.
*/
allScreens?: boolean
/**
* `false`: the logo's file is not fetched and looked at before it is printed (its type by its first bytes,
* at most 512 KB; a deleted or broken file gives the site's name). Default: checked, remembered ten minutes.
*/
checkLogo?: false
/** `false`: no language links on the panel. Default: shown when the panel has more than one language. */
languages?: false
/** `'dark'`: the logo was made for dark grounds (a white logo) and gets no white plate. Default `'light'`. */
logoMadeFor?: 'dark' | 'light'
/** `false`: an SVG logo is not shown on the sign-in screens; the site's name is. Default: shown as a picture. */
svgLogo?: false
/**
* `true`: the logo stands on a white plate — for a logo drawn for light grounds (dark letters). Default:
* no plate, the logo straight on the dark panel, so the panel's logo should be one made for dark grounds.
*/
logoPlate?: boolean
/**
* `true`: an SVG logo is shown too (as a picture, where it cannot run script). Default: only JPEG, PNG,
* WebP, AVIF and GIF are shown; with an SVG logo the sign-in screens show the site's name.
*/
svgLogo?: boolean
}
export type ResolvedSignInLook = { allScreens: boolean; props: SignInLookProps }
@@ -42,10 +53,11 @@ export function resolveSignInLook(whiteLabel: boolean | undefined | WhiteLabelFi
...(wl.logoField ? { imageField: wl.logoField } : {}),
...(wl.inlineImages === false ? { inlineImages: false as const } : {}),
...(signIn.languages === false ? { languages: false as const } : {}),
...(signIn.logoMadeFor === 'dark' ? { logoMadeFor: 'dark' as const } : {}),
...(signIn.checkLogo === false ? { checkLogo: false as const } : {}),
...(signIn.logoPlate === true ? { logoPlate: true as const } : {}),
...(wl.nameField ? { nameField: wl.nameField } : {}),
...(wl.settingsSlug ? { settingsSlug: wl.settingsSlug } : {}),
...(signIn.svgLogo === false ? { svgLogo: false as const } : {}),
...(signIn.svgLogo === true ? { svgLogo: true as const } : {}),
}
return { allScreens: signIn.allScreens === true, props }
}
+5 -3
View File
@@ -773,9 +773,11 @@ export const iapl = (options: IaplOptions): Plugin => {
: pluginGlobals
// The project's globalOverrides win (access, admin, hooks merged; a function = full control).
config.globals = [...(config.globals ?? []), ...applyGlobalOverrides(withRevalidate, options.globalOverrides)]
// `whiteLabel.brandAccess: 'admin'`: the brand the sign-in screens show is changed by admins only.
if (options.whiteLabel && options.whiteLabel !== true && options.whiteLabel.brandAccess === 'admin') {
const wl = options.whiteLabel
// The brand the sign-in screens show (name, logo, icon) is changed by admins only — with the sign-in look,
// unless the project says `brandAccess: 'editor'`; without the look only when it says `'admin'`.
const brandWl = options.whiteLabel === true ? {} : options.whiteLabel
if (brandWl && (brandWl.brandAccess === 'admin' || (brandWl.brandAccess !== 'editor' && resolveSignInLook(brandWl)))) {
const wl = brandWl
config.globals = lockBrandFields(config.globals, wl.settingsSlug ?? 'site-settings', [wl.nameField ?? 'siteName', wl.logoField ?? 'logo', wl.iconField ?? 'favicon'])
}
+4 -2
View File
@@ -447,8 +447,10 @@ export type IaplOptions = {
| {
/**
* Who may change the brand the sign-in screens show (the name, logo and
* icon fields of Site settings). Default `'editor'`: whoever may edit Site
* settings, as before. `'admin'`: field-level access, admins only.
* icon fields of Site settings). Default with the sign-in look: `'admin'`
* (field-level access, admins only; no schema change). `'editor'`: whoever
* may edit Site settings, as before 1.18. With `signIn: false` the default
* is `'editor'`.
*/
brandAccess?: 'admin' | 'editor'
/**
+100 -28
View File
@@ -5,11 +5,11 @@ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, test, vi } from 'vitest'
import { afterEach, describe, expect, test, vi } from 'vitest'
import { adminTexts } from '../src/modules/admin-i18n/index.js'
import { AdminLogo } from '../src/modules/branding/adminGraphics.js'
import { fitLogo, languageLinks, loadSignInBrand, SIGN_IN_LOOK, SIGN_IN_NAME_MAX, signInLogo, signInName, signInProviderActive } from '../src/modules/branding/signIn/brand.js'
import { checkLogoFile, fitLogo, forgetCheckedLogos, languageLinks, loadSignInBrand, SIGN_IN_LOOK, SIGN_IN_NAME_MAX, signInLogo, signInName, signInProviderActive } from '../src/modules/branding/signIn/brand.js'
import { lockBrandFields } from '../src/modules/branding/signIn/brandAccess.js'
import { signInCss } from '../src/modules/branding/signIn/css.js'
import { adminPathFromReferer, buildAdminLanguageEndpoint } from '../src/modules/branding/signIn/languageEndpoint.js'
@@ -38,6 +38,14 @@ const panel = async (props: Parameters<typeof SignInPanel>[0]) => {
const html = renderToStaticMarkup(await SignInPanel(props))
return html.slice(html.indexOf('<header'))
}
const PNG = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 0])
/** The logo's file as the site would answer an anonymous request for it. */
const serve = (body: null | Uint8Array, init: ResponseInit = {}) =>
vi.spyOn(globalThis, 'fetch').mockImplementation(() => Promise.resolve(new Response(body as never, { headers: { 'content-type': 'image/png' }, ...init })))
afterEach(() => {
vi.restoreAllMocks()
forgetCheckedLogos()
})
const fakePayload = (settings: Record<string, unknown>, extra: Record<string, unknown> = {}) =>
({
config: { i18n: { supportedLanguages: { en: {}, pl: {} } }, routes: { api: '/api' }, serverURL: 'https://site.test', ...extra },
@@ -60,11 +68,11 @@ describe('whiteLabel.signIn: the option', () => {
logoField: 'brandLogo',
nameField: 'brandName',
settingsSlug: 'settings',
signIn: { accent: '#0B6E4F', allScreens: true, languages: false, logoMadeFor: 'dark', svgLogo: false },
signIn: { accent: '#0B6E4F', allScreens: true, checkLogo: false, languages: false, logoPlate: true, svgLogo: true },
}),
).toEqual({
allScreens: true,
props: { accent: '#0B6E4F', imageField: 'brandLogo', inlineImages: false, languages: false, logoMadeFor: 'dark', nameField: 'brandName', settingsSlug: 'settings', svgLogo: false },
props: { accent: '#0B6E4F', checkLogo: false, imageField: 'brandLogo', inlineImages: false, languages: false, logoPlate: true, nameField: 'brandName', settingsSlug: 'settings', svgLogo: true },
})
})
@@ -166,23 +174,74 @@ describe('what the public sign-in page may show', () => {
expect(long.endsWith('…')).toBe(true)
})
test('the logo: only an http(s) or site-relative address; SVG out when asked; never enlarged', () => {
expect(signInLogo({ height: 100, url: '/api/media/file/logo.png', width: 400 })).toEqual({ height: 60, src: '/api/media/file/logo.png', width: 240 })
expect(signInLogo({ height: 20, url: 'https://cdn.test/logo.webp', width: 60 })).toEqual({ height: 20, src: 'https://cdn.test/logo.webp', width: 60 })
expect(signInLogo({ url: '/logo.png' })).toEqual({ src: '/logo.png' })
test('the logo: a bitmap by its type, an http(s) or site-relative address, never enlarged; SVG only when asked', () => {
const png = (extra: Record<string, unknown>) => ({ mimeType: 'image/png', ...extra })
expect(signInLogo(png({ height: 100, url: '/api/media/file/logo.png', width: 400 }))).toEqual({ height: 60, src: '/api/media/file/logo.png', width: 240 })
expect(signInLogo({ height: 20, mimeType: 'image/webp', url: 'https://cdn.test/logo.webp', width: 60 })).toEqual({ height: 20, src: 'https://cdn.test/logo.webp', width: 60 })
expect(signInLogo(png({ url: '/logo.png' }))).toEqual({ src: '/logo.png' })
for (const mimeType of ['image/jpeg', 'image/png', 'image/webp', 'image/avif', 'image/gif', 'IMAGE/PNG']) {expect(signInLogo({ mimeType, url: '/l' })).toEqual({ src: '/l' })}
for (const mimeType of ['application/pdf', 'text/html', 'image/x-icon', 'image/tiff', 'video/mp4', undefined, 7]) {expect(signInLogo({ mimeType, url: '/l' })).toBeNull()}
for (const url of ['javascript:alert(1)', 'data:text/html,<script>1</script>', '//evil.test/x.png', 'file:///etc/passwd', '', ' ']) {
expect(signInLogo({ url })).toBeNull()
expect(signInLogo(png({ url }))).toBeNull()
}
expect(signInLogo('64f0…id-only')).toBeNull()
expect(signInLogo(null)).toBeNull()
const svg = { mimeType: 'image/svg+xml', url: '/api/media/file/logo.svg' }
expect(signInLogo(svg)).toEqual({ src: svg.url })
expect(signInLogo(svg, { svgLogo: false })).toBeNull()
expect(signInLogo({ mimeType: 'image/png', url: '/api/media/file/renamed.SVG?v=2' }, { svgLogo: false })).toBeNull()
expect(signInLogo(svg)).toBeNull()
expect(signInLogo(svg, { svgLogo: true })).toEqual({ src: svg.url })
expect(signInLogo(png({ url: '/api/media/file/renamed.SVG?v=2' }))).toBeNull()
expect(fitLogo(1000, 100)).toEqual({ height: 24, width: 240 })
expect(fitLogo(0, 10)).toBeNull()
})
test('the served file: the smallest generated size at least twice the shown width, same proportions, an allowed type', () => {
const logoDoc = (sizes: Record<string, unknown>) => ({ height: 400, mimeType: 'image/png', sizes, url: '/full.png', width: 1600 })
const size = (width: number, height: number, url: string, mimeType = 'image/webp') => ({ height, mimeType, url, width })
// shown 240 wide: 480 or more
expect(signInLogo(logoDoc({ card: size(768, 192, '/768.webp'), hero: size(1200, 300, '/1200.webp'), thumb: size(300, 75, '/300.webp') }))?.src).toBe('/768.webp')
expect(signInLogo(logoDoc({ square: size(600, 600, '/crop.webp'), thumb: size(300, 75, '/300.webp') }))?.src).toBe('/full.png')
expect(signInLogo(logoDoc({ bad: size(600, 150, 'javascript:1'), empty: null, svg: size(600, 150, '/x.svg', 'image/svg+xml') }))?.src).toBe('/full.png')
expect(signInLogo(logoDoc({}))).toEqual({ height: 60, src: '/full.png', width: 240 })
})
test('the file is looked at before it is printed: a deleted, broken, foreign or too large file gives the name', async () => {
const settings = { logo: { height: 160, mimeType: 'image/png', url: '/api/media/file/logo.png', width: 560 }, siteName: 'Acme' }
const brand = () => {
forgetCheckedLogos()
return loadSignInBrand({ look: {}, payload: fakePayload(settings) })
}
serve(PNG)
expect((await brand()).logo?.src).toBe(settings.logo.url)
vi.restoreAllMocks()
serve(null, { status: 404 })
expect(await brand()).toEqual({ name: 'Acme', logo: null })
vi.restoreAllMocks()
serve(new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>')) // says image/png, is not
expect((await brand()).logo).toBeNull()
vi.restoreAllMocks()
serve(new TextEncoder().encode('<html>'), { headers: { 'content-type': 'text/html' } })
expect((await brand()).logo).toBeNull()
vi.restoreAllMocks()
serve(PNG, { headers: { 'content-length': String(600 * 1024), 'content-type': 'image/png' } })
expect((await brand()).logo).toBeNull()
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)
vi.restoreAllMocks()
// one look per address in ten minutes, and none with checkLogo: false
const fetched = serve(PNG)
forgetCheckedLogos()
await loadSignInBrand({ look: {}, payload: fakePayload(settings) })
await loadSignInBrand({ look: {}, payload: fakePayload(settings) })
expect(fetched).toHaveBeenCalledTimes(1)
forgetCheckedLogos()
await loadSignInBrand({ look: { checkLogo: false }, payload: fakePayload(settings) })
expect(fetched).toHaveBeenCalledTimes(1)
expect(await checkLogoFile('ftp://site.test/logo.png', null)).toBe('bad')
expect(await checkLogoFile('/relative.png', null)).toBe('unknown')
})
test('markup in the name is text; the only links are the site, and the language endpoint', async () => {
const payload = fakePayload({ siteName: '<script>alert(1)</script> <a href="https://evil.test">reset</a> https://evil.test' })
const html = await panel({ i18n: { language: 'en', t: t as never }, look: {}, payload })
@@ -195,14 +254,15 @@ describe('what the public sign-in page may show', () => {
expect(html).toContain('<span aria-current="true" lang="en">English</span>')
})
test('a logo: an <img> with the name as its text and its size, on a plate unless made for dark grounds', async () => {
test('a logo: an <img> with the name as its text and its size, straight on the panel; a plate when asked', async () => {
serve(PNG)
const payload = fakePayload({ logo: { height: 160, mimeType: 'image/png', url: '/api/media/file/logo.png', width: 560 }, siteName: 'Acme' })
const html = await panel({ look: { languages: false }, payload })
expect(html).toContain('<img alt="Acme" decoding="async" height="69" src="/api/media/file/logo.png" width="240"/>')
expect(html).toContain('iapl-signin__brand--plate')
expect(html).toContain('<a class="iapl-signin__brand" href="/">')
expect(html).not.toContain('iapl-signin__brand--plate')
expect(html).not.toContain('<nav')
const dark = await panel({ look: { logoMadeFor: 'dark' }, payload })
expect(dark).not.toContain('iapl-signin__brand--plate')
expect(await panel({ look: { logoPlate: true }, payload })).toContain('iapl-signin__brand--plate')
})
test('nothing set, or no database: the label only — no vendor, no Payload', async () => {
@@ -218,13 +278,23 @@ describe('what the public sign-in page may show', () => {
})
test('a session that owes its 2FA code never gets the media address: the picture itself, or the name', async () => {
const settings = { logo: { url: 'https://site.test/api/media/file/logo.png' }, siteName: 'Acme' }
const payload = fakePayload(settings, { custom: {} })
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(new Uint8Array([1, 2, 3]), { headers: { 'content-type': 'image/png' } }))
// no 2FA guard configured in this fake: a signed-in user counts as passed, the address is used
expect((await loadSignInBrand({ look: {}, payload, user: { id: 1, collection: 'users' } })).logo?.src).toBe(settings.logo.url)
fetchSpy.mockRestore()
expect((await loadSignInBrand({ look: {}, payload })).logo?.src).toBe(settings.logo.url)
const settings = { logo: { mimeType: 'image/png', url: 'https://site.test/api/media/file/logo.png' }, siteName: 'Acme' }
const guarded = () => fakePayload(settings, { custom: { ipal: { twoFactor: { collection: 'users', requireSetup: true } } } })
const pending = { id: 1, _strategy: 'local-jwt', collection: 'users', hasTotp: true }
const brandFor = (look: Record<string, unknown>, user?: Record<string, unknown>) => {
forgetCheckedLogos()
return loadSignInBrand({ look, payload: guarded(), user })
}
serve(PNG)
expect((await brandFor({}, pending)).logo?.src).toBe(`data:image/png;base64,${Buffer.from(PNG).toString('base64')}`)
expect((await brandFor({}, { ...pending, _strategy: 'totp' })).logo?.src).toBe(settings.logo.url)
expect((await brandFor({})).logo?.src).toBe(settings.logo.url)
// never fetched for it (inlineImages: false), not checked (checkLogo: false), or nothing answers: the name
expect((await brandFor({ inlineImages: false }, pending)).logo).toBeNull()
vi.restoreAllMocks()
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('ECONNREFUSED'))
expect((await brandFor({}, pending)).logo).toBeNull()
expect((await brandFor({ checkLogo: false }, pending)).logo).toBeNull()
})
test('the stylesheet: no file, no font, no other host, no script; honours reduced motion and forced colours', () => {
@@ -306,10 +376,11 @@ describe('whiteLabel.brandAccess', () => {
})
const fieldsOf = (global: GlobalConfig) => (global.fields[0] as { tabs: { fields: { access?: { update?: (a: unknown) => Promise<boolean> }; name: string }[] }[] }).tabs[0].fields
test('the default leaves the fields as they are; "admin" locks the brand fields only, without a new field', async () => {
const config = await build({ whiteLabel: true })
const plain = config.globals!.find((g) => g.slug === 'site-settings')!
expect(JSON.stringify(plain.fields)).toBe(JSON.stringify((await build()).globals!.find((g) => g.slug === 'site-settings')!.fields))
test('with the sign-in look the brand fields are admin-only; "editor" or no look leaves them as they were', async () => {
const fieldsJson = async (options: Record<string, unknown>) => JSON.stringify((await build(options)).globals!.find((g) => g.slug === 'site-settings')!.fields)
const plain = await fieldsJson({})
expect(await fieldsJson({ whiteLabel: { brandAccess: 'editor' } })).toBe(plain)
expect(await fieldsJson({ whiteLabel: { signIn: false } })).toBe(plain)
const locked = lockBrandFields([settings(), { slug: 'other', fields: [{ name: 'siteName', type: 'text' }] }], 'site-settings', ['siteName', 'logo', 'favicon'])
const [siteName, description, logoField] = fieldsOf(locked[0])
@@ -319,11 +390,12 @@ describe('whiteLabel.brandAccess', () => {
for (const field of [siteName, logoField]) {
expect(await field.access!.update!({ req: { payload: staff, user: null } })).toBe(false)
}
// no field is added or removed: nothing for a database to migrate
expect(fieldsOf(locked[0]).map((f) => f.name)).toEqual(['siteName', 'siteDescription', 'logo'])
})
test('through the plugin: an editor may not change the name, an admin may', async () => {
const config = await build({ whiteLabel: { brandAccess: 'admin' } }, { collections: [{ slug: 'users', auth: true, fields: [] }, { slug: 'media', fields: [], upload: true }] } as never)
const config = await build({ whiteLabel: true }, { collections: [{ slug: 'users', auth: true, fields: [] }, { slug: 'media', fields: [], upload: true }] } as never)
const global = config.globals!.find((g) => g.slug === 'site-settings')!
const find = (fields: unknown[], name: string): { access?: { update?: (a: unknown) => Promise<boolean> } } | undefined => {
for (const f of fields as { fields?: unknown[]; name?: string; tabs?: { fields: unknown[] }[] }[]) {