Browser protections
Beacon serves a web application and a cookie-authenticated API. A browser sends the session cookie with every request to Beacon, including requests started by a page on another site. The protections on this page stop that page from reading Beacon’s responses, framing Beacon, forging writes in a user’s name or reaching Beacon under a host name you did not configure.
Read this page when you put Beacon behind a reverse proxy, when you enable OriginGuard enforcement, when your host application embeds Beacon’s single-page app (SPA), or when a browser console reports a blocked resource on a Beacon page.
There are four protections:
| Protection | What it blocks | Where it runs |
|---|---|---|
| Security response headers | Content sniffing, framing, referrer leaks, device features | Every Beacon response |
| Content-Security-Policy (CSP) | Scripts, styles, frames and connections from other origins | Responses under /beacon |
| Host and Origin check | Cross-site writes, cross-site WebSockets, DNS rebinding | State-changing, realtime-hub and anonymous requests |
| Antiforgery token | Forged writes that carry the session cookie | Non-GET requests from a signed-in browser session |
All of them act on Beacon’s own routes only: /beacon and the prefixes in Beacon:Authentication:AdditionalPaths. Your own routes keep whatever your application sends. See Where Beacon credentials apply.
Response headers
Section titled “Response headers”The middleware writes these headers when the response starts, so error pages and static files carry them too. It uses TryAdd: a header the response already carries is kept. A host or an endpoint can therefore send its own value and Beacon will not overwrite it.
| Header | Exact value | Notes |
|---|---|---|
X-Content-Type-Options | nosniff | |
X-Frame-Options | DENY | Not added when the response already has a Content-Security-Policy that names frame-ancestors (the embed page decides who may frame it). |
Referrer-Policy | strict-origin | Not no-referrer: under no-referrer a browser sends Origin: null on the SPA’s own POSTs, and the origin check would refuse them. |
Permissions-Policy | accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=() | Turns the listed device features off. |
Content-Security-Policy | see below | Only under /beacon, and only in Enforce mode. |
HSTS is the host’s job
Section titled “HSTS is the host’s job”Beacon does not send Strict-Transport-Security. HSTS binds a whole host name, and Beacon shares that name with your application. Send it from the host (or the proxy):
if (!app.Environment.IsDevelopment()){ app.UseHsts();}
app.UseHttpsRedirection();
// Optional: Beacon's middleware pipeline adds this itself when you leave it out.// Call it early so the SPA's static files carry the headers too.app.UseBeaconSecurityHeaders();
app.UseStaticFiles();app.UseBeaconPipeline();The reference host calls UseBeaconSecurityHeaders() before UseStaticFiles() for this reason. UseBeaconAuthentication() adds the headers itself when you do not call it, and calling it twice is harmless.
Content-Security-Policy
Section titled “Content-Security-Policy”Beacon:Security:Csp chooses how Beacon sends the policy.
| Key | Type | Default | Range | What it does |
|---|---|---|---|---|
Beacon:Security:Csp | enum | Enforce | Enforce, ReportOnly, Off | Enforce sends Content-Security-Policy: the browser blocks what the policy refuses. ReportOnly sends Content-Security-Policy-Report-Only: the browser logs violations in its console and blocks nothing. Off sends no policy; the other headers are still sent. |
The policy, exactly as the code builds it:
default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; worker-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'In plain words:
- Scripts, workers, fonts and connections load only from Beacon’s own origin. Nothing loads from a CDN.
- Styles may be inline, because the SQL editor and the diagram renderer inject style elements.
- Images may be
data:URIs (editor icons). - Plugins (
object-src) are off,<base>may only point at Beacon, forms may only post to Beacon. - No page can frame Beacon (
frame-ancestors 'none').
The policy is sent on /beacon paths only. A path that is Beacon’s only because of AdditionalPaths (for example /warp) gets the four other headers but no CSP.
If the response already has a Content-Security-Policy or a Content-Security-Policy-Report-Only header, in either form, Beacon sends nothing of its own. That is how you replace the policy:
app.Use(async (context, next) =>{ if (context.Request.Path.StartsWithSegments("/beacon")) { context.Response.OnStarting(() => { context.Response.Headers.ContentSecurityPolicy = "default-src 'self'; script-src 'self'; connect-src 'self' https://telemetry.example.com; frame-ancestors 'none'"; return Task.CompletedTask; }); }
await next();});Register that middleware after UseBeaconSecurityHeaders(). OnStarting callbacks run in reverse order of registration, so yours runs first, and Beacon’s callback then sees your header and keeps it.
Moving from ReportOnly to Enforce
Section titled “Moving from ReportOnly to Enforce”Use this when a proxy, a browser extension policy or a host customisation might load something the policy refuses.
- Set
Beacon:Security:CsptoReportOnlyin the environment you test in. - Use Beacon in a browser with the developer console open: sign in, open the query editor, open a diagram, open the admin pages.
- Look for console messages that start with
[Report Only] Refused to .... Each names the directive and the blocked URL. - If there are none, set
CsptoEnforce(or remove the key;Enforceis the default). - If there are some, find where the blocked resource is added. A proxy that injects a script, for example, needs to stop doing so, or you send your own policy as shown above.
{ "Beacon": { "Security": { "Csp": "ReportOnly" } }}Environment variable form:
Beacon__Security__Csp=ReportOnlyThe Host and Origin check
Section titled “The Host and Origin check”A page on another site can make a browser send a POST to Beacon with the user’s cookie. The check refuses such a request by comparing the Origin header, and the Host header, with the origins you configured.
Settings
Section titled “Settings”| Key | Type | Default | Range | What it does |
|---|---|---|---|---|
Beacon:Security:OriginGuard | enum | LogOnly | LogOnly, Enforce | LogOnly: a request the check would refuse goes on and a warning is logged. Enforce: the request is answered 403. |
Beacon:Security:AllowedOrigins | string list | empty | each entry an http or https origin: scheme, host, optional port, no path, query or fragment (a trailing / is ignored) | The origins browsers reach Beacon from. |
Beacon:PublicBaseUrl | URL | unset | an absolute http or https URL; its path is not part of the origin | Its origin is added to the allowed origins. Also used by the MCP discovery documents. |
An entry that is not a valid origin stops the application at startup. The message names the entry:
Beacon:Security:AllowedOrigins:0 must be an http or https origin such as https://beacon.example.com: a scheme, a host and an optional port, without a path, query or fragment.When neither AllowedOrigins nor PublicBaseUrl yields an origin, the allowed origin is the request’s own: its scheme and Host, after the host’s forwarded headers. When at least one is configured, they replace that default.
{ "Beacon": { "PublicBaseUrl": "https://beacon.example.com", "Security": { "OriginGuard": "Enforce", "AllowedOrigins": [ "https://beacon.example.com", "https://beacon-admin.example.com:8443" ] } }}Beacon__Security__OriginGuard=EnforceBeacon__Security__AllowedOrigins__0=https://beacon.example.comWhich requests are checked
Section titled “Which requests are checked”A request on a Beacon route is checked when it is any of these:
- State-changing: any method other than
GET,HEAD,OPTIONSandTRACE. - A request to the realtime hub,
/beacon/api/hub(the negotiate call and the WebSocket upgrade). - Sent to an anonymous endpoint (sign-in, first-run setup, health).
Everything else passes. For a checked request the rules are, in order:
- Authorization header. A request that carries an
Authorizationheader (API key, bearer token) passes. A page on another origin cannot add that header without a CORS preflight, so only cookie-authenticated requests need the check. - Host. With configured origins, a request that looks like it came from a browser (it has an
Originor aSec-Fetch-Siteheader) must arrive with aHostthat matches one of them. AHostwithout a port matches an origin on its scheme’s default port (80 or 443). Hosts are compared in punycode form. Without configured origins this step does not run, so there is no DNS-rebinding protection. - Origin. For state-changing and hub requests, the
Originmust be one of the allowed origins. The opaque originnullis never allowed. - No Origin. For state-changing and hub requests with no
Origin, theSec-Fetch-Siteheader must not becross-siteorsame-site.
Requests that no browser sent (no Origin, no Sec-Fetch-Site: scripts, API-key clients, MCP clients, health probes) pass.
An OpenID Connect scheme’s own paths also pass: its callback, signed-out callback and remote sign-out path. The identity provider posts there from its own origin. The check runs after UseAuthentication, so a remote sign-in callback is answered first.
In the MCP gateway, the check runs before routing, so the anonymous-endpoint rule does not apply there. The state-changing and hub rules do.
What a refusal looks like
Section titled “What a refusal looks like”Verdicts: ForeignHost, ForeignOrigin (including a null origin) and CrossSiteRequest (no Origin, cross-site fetch).
In Enforce mode the response is:
HTTP/1.1 403 ForbiddenContent-Type: application/problem+json
{ "type": "https://tools.ietf.org/html/rfc9110#section-15.5.4", "title": "Forbidden", "status": 403, "detail": "The request's origin is not allowed.", "traceId": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00"}The log line is a warning with no event id:
The Beacon origin check refused POST /beacon/api/queries (ForeignOrigin).In LogOnly mode the request is let through and the warning reads:
The Beacon origin check would refuse POST /beacon/api/queries (ForeignOrigin); the request was let through because Beacon:Security:OriginGuard is LogOnly. List the origins browsers use in Beacon:Security:AllowedOrigins or Beacon:PublicBaseUrl.The method and path are written on one line without control characters, at most 256 characters each. Nothing else about the request, such as the Origin value, is logged.
Rollout: LogOnly to Enforce
Section titled “Rollout: LogOnly to Enforce”-
Set the public origin. Set
Beacon:PublicBaseUrlto the address users type, or list every address inBeacon:Security:AllowedOrigins. List each name a browser uses: the public name, an internal name, a name with a non-default port. -
Keep
OriginGuardatLogOnlyand run a full release. Use the application normally, including SSO sign-in and any scripts that act on a user’s cookie. -
Search the logs for
The Beacon origin check would refuse. Each line is a request that would be refused once enforced. Decide for each: is the origin one you own? Add it toAllowedOrigins. Is it an unknown site? Then the check is doing its work. -
Repeat until a normal week has no such lines.
-
Set
OriginGuardtoEnforce. If no origin is configured at this point, Beacon logs this warning at startup:Beacon:Security:OriginGuard is Enforce but no origin is configured (Beacon:Security:AllowedOrigins, Beacon:PublicBaseUrl), so the check compares each Origin with the request's own scheme and Host. Behind a TLS-terminating proxy that does not forward the scheme every browser write is refused, and without configured origins the Host check does not run, so it gives no DNS-rebinding protection. -
After the change, watch for
The Beacon origin check refusedand for 403 responses with the detailThe request's origin is not allowed.
Antiforgery tokens
Section titled “Antiforgery tokens”Antiforgery protects the cookie-authenticated API from forged writes. Beacon issues a token to the signed-in browser; the browser must send it back in a header on every write.
Which requests need the token
Section titled “Which requests need the token”| Request | Token required |
|---|---|
GET, HEAD, OPTIONS | No |
| Anonymous non-GET request | No, except POST /beacon/api/auth/login and POST /beacon/api/auth/logout, which need it even for anonymous callers |
| Non-GET request from a signed-in browser session | Yes |
A request authenticated by an Authorization header (API key, bearer token) | No. A browser does not send these on its own, so such a request cannot be forged. |
Sign-out needs the token for anonymous callers too. A cross-site form post arrives without the SameSite=Lax session cookie, yet the sign-out answer would still delete that cookie. Without a valid token nothing is signed out and no cookie is emitted.
How the browser gets and sends it
Section titled “How the browser gets and sends it”- The SPA calls
GET /beacon/api/csrf. The response sets two cookies and returns the token in the body:.Beacon.Antiforgery: HttpOnly, holds the cookie half of the token pair. The name is Beacon’s own, so it does not collide with a host cookie of the default name.XSRF-TOKEN: readable by JavaScript,SameSite=Lax,Securewhen the request is HTTPS, path/.
- On every write the SPA sends the token in the
X-XSRF-TOKENrequest header. - After sign-in and sign-out Beacon issues a fresh token bound to the new identity. When a stale token gets the 400 below, the SPA fetches a new one and retries once.
GET /beacon/api/csrf HTTP/1.1Cookie: Beacon.Auth=...{ "token": "<antiforgery request token>" }A caller authenticated with an Authorization header gets no token. GET /beacon/api/csrf answers 400 with the title Antiforgery tokens are issued to browser sessions only. and the detail Requests authenticated with an Authorization header do not need an antiforgery token.
A host that embeds the SPA
Section titled “A host that embeds the SPA”AddApi() sets the antiforgery header name to X-XSRF-TOKEN and the cookie name to .Beacon.Antiforgery. Antiforgery options are shared by the whole application, so these two settings apply to your own forms too.
If your host configures antiforgery with its own header name, for example RequestVerificationToken, Beacon still accepts the SPA’s X-XSRF-TOKEN. It copies that header’s value into your header name before validating. Only the header name is bridged; the token is still validated against the antiforgery cookie and the caller’s identity.
Beacon’s UseBeaconPipeline() includes UseAntiforgery() in the order Beacon needs (after authentication, so tokens are issued for the signed-in user). Do not move it. See Host setup.
The failure response
Section titled “The failure response”HTTP/1.1 400 Bad RequestContent-Type: application/problem+json
{ "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1", "title": "Invalid antiforgery token.", "status": 400, "detail": "<message from the framework, for example: The required antiforgery header value \"X-XSRF-TOKEN\" is not present.>"}The detail is the framework’s own message, so its wording depends on the failure (missing header, missing cookie, token for another identity). The server logs a warning:
Antiforgery validation failed for POST /beacon/api/queries (<failure code>)The log names the failure by code only; it never includes the token.
Session cookie flags
Section titled “Session cookie flags”The Beacon.Auth session cookie is HttpOnly, SameSite=Lax, and Secure as the request arrives, or always with Beacon:Authentication:Cookie:SecureAlways. The flags, the plain-HTTP startup warning and the sign-in settings are on Sign-in and session hardening.
The embed page
Section titled “The embed page”The anonymous embed page (GET /beacon/embed/{publicId}) is the one Beacon page meant to be framed. It sends its own response headers, and SecurityHeadersMiddleware keeps them:
| Header | Value |
|---|---|
Content-Security-Policy | default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self' data:; font-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors <origins> |
Referrer-Policy | no-referrer |
Cache-Control | no-store |
X-Content-Type-Options | nosniff |
<origins> is the list of https frame origins stored on the grant, separated by spaces. A grant with no origin, or one that is not live, gets frame-ancestors 'none'. Because the response names frame-ancestors, Beacon does not add X-Frame-Options: DENY. See Embedding.
Proxied deployments
Section titled “Proxied deployments”Behind a reverse proxy that terminates TLS, three things decide whether these protections work:
-
Beacon:PublicBaseUrl. Set it to the public https address. Without it the origin check compares eachOriginwith the request’s own scheme andHost. Both come from the request, which a client or a misconfigured proxy influences. Beacon also logs, at startup, once the MCP discovery routes are mapped:Beacon:PublicBaseUrl is not configured — MCP discovery documents and WWW-Authenticate challenges will reflect the request Host header. Set Beacon:PublicBaseUrl on public deployments so advertised URLs cannot be influenced by the caller. -
Forwarded headers. The host must run
UseForwardedHeadersfirst in the pipeline, listing only your proxies, so the request’s scheme ishttpsand the client address is the real one. Without the scheme, a request made over https looks like http to Beacon: the cookie loses itsSecureflag unlessSecureAlwaysis on, and theOrigincomparison without configured origins fails.var forwarded = new ForwardedHeadersOptions{ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto};forwarded.KnownProxies.Clear();forwarded.KnownNetworks.Clear();forwarded.KnownProxies.Add(IPAddress.Parse("10.0.0.5"));app.UseForwardedHeaders(forwarded);The reference host wraps the same code in a switch:
Beacon:ForwardedHeaders:Enabledand aBeacon:ForwardedHeaders:KnownProxieslist. Those two keys belong to the sample host, not to the Beacon packages. An empty proxy list trusts none, so the headers are ignored (fails safe). -
AllowedHosts. The ASP.NET CoreAllowedHostssetting defaults to*. Set it to your real host names. It is the host’s own filter, and it works with the Host check above.
Recommended values
Section titled “Recommended values”| Setting | Development | Production | Regulated |
|---|---|---|---|
Beacon:Security:Csp | Enforce (default) | Enforce | Enforce or unset |
Beacon:Security:OriginGuard | LogOnly (default) | Enforce after a clean LogOnly release | Enforce |
Beacon:Security:AllowedOrigins | empty | the public origins, if more than PublicBaseUrl | list every origin first |
Beacon:PublicBaseUrl | unset | your public https address | required, https |
Beacon:Authentication:Cookie:SecureAlways | off | on | on |
With Beacon:Profile = Regulated, the startup check fails, listing all findings in one message, when any of these hold (from RegulatedProfile.Assess):
Beacon:Security:Cspis set to anything butEnforce(unset is accepted). Message:must be Enforce (or unset): browsers do not block what Beacon's Content-Security-Policy refuses.Beacon:Security:OriginGuardis notEnforce. Message:must be Enforce (list the origins browsers use in Beacon:Security:AllowedOrigins first): a request from another origin is only logged.Beacon:PublicBaseUrlis not an https URL. Message:must be set to Beacon's https address: links, discovery documents and the origin check otherwise follow the request's Host header.Beacon:Authentication:Cookie:SecureAlwaysis not true. The profile fills it when you leave it unset.
The profile judges Csp and OriginGuard on the bound options, so a value set in code with Configure or PostConfigure counts as one set in configuration. The profile never overrides a value you configured.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
403 The request's origin is not allowed. on every save after switching to Enforce | The browser’s Origin is not in the allowed list. Common cause: a proxy that does not forward the scheme, so the “own origin” is http://... while the browser sends https://.... | Set Beacon:PublicBaseUrl or AllowedOrigins. Run UseForwardedHeaders. |
| Same 403, only on a second host name or port | That name is not listed. With configured origins, the Host must match one of them. | Add the origin, including a non-default port, to AllowedOrigins. |
Startup fails: Beacon:Security:AllowedOrigins:0 must be an http or https origin... | The entry has a path, query, fragment, user info, a non-http scheme or is not a URL. | Use https://host or https://host:port. |
Warning: Beacon:PublicBaseUrl is not an absolute http or https URL, so the Beacon origin check does not count it as an allowed origin. | The value is a bare host name or another scheme. | Write the full URL, for example https://beacon.example.com. |
400 Invalid antiforgery token. after a long idle time or a sign-in in another tab | The token is bound to the identity that fetched it. | Reload the page. The SPA retries once on its own. |
400 Invalid antiforgery token. from your own script that uses the session cookie | The script sends no X-XSRF-TOKEN. | Use an API key or bearer token instead, or fetch GET /beacon/api/csrf and send the token. |
Blank page; console says Refused to load the script ... Content-Security-Policy | Something injects a script (proxy, extension, host middleware). | Test with ReportOnly, remove the injection, or send your own policy. |
Beacon embedded in an <iframe> is blank | frame-ancestors 'none' and X-Frame-Options: DENY. This is by design. | Frame only the embed page, which has its own frame-ancestors list. |
The origin warning appears for a request from a script that sends Origin | A script copied browser headers. | Authenticate it with an API key: requests with an Authorization header are not checked. |
Related pages
Section titled “Related pages”- Sign-in and session hardening: the cookie, sessions and SSO settings.
- Rate limits and request limits: per-address limits and why forwarded headers matter.
- Host setup: the middleware pipeline and its order.
- Production checklist: the reverse-proxy and HSTS checklist.
- Embedding: the embed page and its frame origins.
- Configuration reference: the settings in one table.