Public HTML Safety Contract
Public Capell pages must look like ordinary public HTML to every non-admin visitor.
This applies to anonymous users, signed-in non-admin users, crawlers, cached HTML, static exports, previews served outside the admin, and CDN copies.
Gold Standard
Section titled “Gold Standard”A safe public response has these properties:
- the HTML can be served unchanged to anonymous visitors, signed-in non-admin users, admins, crawlers, static exports, and CDN cache;
- admin editing controls are added only after page load by an authenticated admin beacon response;
- public Blade receives prepared data and does not discover editor state on its own;
- cacheable HTML does not contain anything that would help a visitor infer the editor, schema, package, or admin URL structure.
The diagram is generated from the canonical Mermaid source. It is a conceptual contract: hydrated render data supports public Blade, while controls are added only by the authenticated authoring path and are not part of public/cache output.
Which gate rejects a response, and which gate bypasses caching? Public render assertions throw on a contract violation; they do not convert a violation into a private page. The separate, optional HTML Cache middleware evaluates response eligibility and can apply private, no-store delivery. A cache hit can serve existing output without this render path. Admin preview and the optional post-load authoring beacon have their own access boundaries. This diagram does not prove runtime leak prevention or cache behaviour.
Never Expose
Section titled “Never Expose”Public HTML must not contain:
- authoring controls, editor scripts, or admin toolbar markup;
- model IDs, field paths, permissions, package names, or internal selectors;
- signed Filament editor URLs;
- editable markers or data attributes that reveal admin structure;
- hidden admin-only labels or diagnostics;
- lazy-loaded database state from public Blade views.
In-page authoring is a post-load admin feature. The public page loads normally, then an authenticated admin beacon may add edit controls for that admin session only.
Where To Enforce It
Section titled “Where To Enforce It”| Area | Rule |
|---|---|
| Public Blade | Receive hydrated render data. Do not query models or lazy-load relationships. |
| Render hooks | Add only safe public markup. Do not output authoring selectors or package internals. |
| Page cache | Refuse to cache unsafe responses. Treat bypass headers as a bug to fix. |
| Themes | Keep theme output public. Admin editing controls belong in frontend-authoring. |
| Packages | Test anonymous and non-admin output when the package renders public HTML. |
RenderHtmlContentAction sanitises through Core’s SanitizesPublicHtml contract with the
RichText profile. Markup beyond that profile is declared once at boot as an
HtmlSanitizerProfileExtension on HtmlSanitizerProfileRegistry, which refuses event
handlers, inline styles, unvalidated URL attributes and other forbidden markup. Extensions
are application-global: they must not vary by site, tenant, request, or authenticated user.
Head Snippets
Section titled “Head Snippets”Site, theme and page meta_tags accept <meta> and <link> elements only. Capell removes
every other element, event handler attribute and javascript:, data: or vbscript: URL.
It also drops <meta http-equiv> tags set to refresh, set-cookie or
content-security-policy (and the report-only variant), because an editor must not be able to
redirect visitors or rewrite the response policy. A <link> is kept only when every rel token
is one of alternate, apple-touch-icon, apple-touch-icon-precomposed, author,
canonical, dns-prefetch, icon, license, manifest, mask-icon, me, next,
preconnect, prev, search or shortcut. Stylesheets, preloads and module preloads are not
available to editors; themes and packages add those through the frontend resource plan.
Response Security Headers
Section titled “Response Security Headers”Capell\Frontend\Http\Middleware\SecurityResponseHeaders is the outermost middleware of the
public route group, so a Core-only install sends X-Content-Type-Options: nosniff,
X-Frame-Options: SAMEORIGIN, Referrer-Policy: strict-origin-when-cross-origin,
Permissions-Policy and X-Permitted-Cross-Domain-Policies: none on public pages, including
rejections and redirects. It adds Strict-Transport-Security on secure requests when
security.headers.hsts.enabled is true. It sends no Content-Security-Policy.
Each header is set only when the response does not already carry it, so a route, an inner
middleware or a host application that sets its own value keeps it. Set
security.headers.enabled to false to turn the middleware off entirely, or remove it with
FrontendRouteMiddlewareRegistry.
Safe And Unsafe Examples
Section titled “Safe And Unsafe Examples”Safe:
<article> <h1>{{ $pageTitle }}</h1> <div>{{ $summary }}</div></article>Unsafe:
<article data-capell-editor="page" data-model-id="{{ $page->id }}" data-field-path="content.hero.title"> <a href="{{ $signedEditorUrl }}">Edit</a> {{ $page->title }}</article>The unsafe example leaks model identity, field paths, editor selectors, and a signed admin URL into public HTML. It is unsafe even if the element is visually hidden.
Debugging Checklist
Section titled “Debugging Checklist”Fetch the page as an anonymous user:
curl -s https://example.test/ > /tmp/capell-public.htmlrg "filament|signed|field_path|data-capell|model_id|permission|authoring" /tmp/capell-public.htmlThis broad search is triage: a match is a prompt to inspect the rendered HTML,
not proof of a leak. For example, data-capell-widget-assets="example" is an
allowed runtime attribute used to load public widget assets. Keep that wiring.
By contrast, data-capell-authoring="page:1" exposes authoring state and must
not appear in public output, even on a hidden element.
Use the PublicHtmlSafetyInspector for the executable policy. Its behaviour tests cover allowed runtime attributes and forbidden authoring markers. The route-backed safety tests exercise real public responses; keep their presence and absence assertions when changing a render path. A successful broad search alone does not replace those checks.
Then check cache behaviour:
curl -I https://example.test/If the response bypasses cache because unsafe HTML was detected, fix the render path rather than forcing cache.
Test Checklist
Section titled “Test Checklist”For rendering, cache, theme, beacon, or public package changes, test both presence and absence:
- expected public content is present;
- authoring controls are absent for anonymous users;
- admin URLs, model IDs, field paths, permissions, and selectors are absent;
- cached/static HTML matches the anonymous-safe output;
- public Blade does not rely on relationship fallback queries.
Test Recipes
Section titled “Test Recipes”it('serves anonymous-safe public html', function (): void { $response = $this->get('/example-page');
$response->assertOk();
expect($response->getContent()) ->not->toContain('data-capell-editor') ->not->toContain('field_path') ->not->toContain('filament') ->not->toContain('signed');});it('does not lazy load relationships while rendering public pages', function (): void { Model::preventLazyLoading();
$this->get('/example-page')->assertOk();});it('keeps cached html identical to anonymous-safe output', function (): void { $first = $this->get('/example-page')->getContent(); $second = $this->get('/example-page')->getContent();
expect($second)->toBe($first) ->and($second)->not->toContain('data-capell-editor');});