Class NextDashboardSecurityHeaders
java.lang.Object
com.kingsrook.qqq.middleware.javalin.routeproviders.NextDashboardSecurityHeaders
Security response headers for the QQQ Next dashboard (QRun-IO/qqq#695).
The defaults are strict and match what the static export needs:
- Content-Security-Policy: everything from the application's own origin;
inline scripts only by the SHA-256 hash of each script in the served page
(the provider adds these per document); no plugins, no base-URI or form
targets elsewhere, and the dashboard may not be framed. Inline styles are
allowed: the UI's dialog scroll lock, toasts and React style hoisting
create style elements at runtime, and branding customCss is applied as a
style element. Images may also come from any HTTPS origin (branding logos
and image fields hold external URLs).
- X-Frame-Options DENY (for browsers without frame-ancestors).
- Referrer-Policy strict-origin-when-cross-origin: other origins see only the
application origin, never a path or query (such as an authorization code).
- Permissions-Policy: device and sensor features the dashboard never uses
are disabled.
- X-Content-Type-Options nosniff.
NextDashboardRouteProvider adds the configured identity provider origins to
connect-src (OAUTH2 discovery, AUTH_0 token exchange), the QuickSight
origin to frame-src when the instance has a quickSightChart widget, the
origin of each customComponent widget's componentSourceUrl to script-src,
and, only for the analytics providers the instance configures (QQQ_ENV_*
GOOGLE_ANALYTICS_*, POSTHOG_*, ANALYTICS_PLUGIN_SCRIPTS; QRun-IO/qqq#730),
their script origins to script-src and the origins they send to to
connect-src (see NextDashboardAnalyticsOrigins). When both Google Drive
browser settings are configured, Google identity and picker script, frame,
connect and style sources are added as well.
Applications change the policy with
QApplicationJavalinServer.withNextDashboardSecurityHeadersCustomizer, which
receives this object after those additions.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildContentSecurityPolicy(Collection<String> scriptHashes) The policy for one document, with the hashes of its inline scripts added to script-src.Name of the policy header: Content-Security-Policy, the report-only variant, or null when the policy is disabled.The non-CSP headers, in order.getSources(String directive) The sources of a directive, in order (empty when the directive is absent).static StringThe origin (scheme://host[:port]) of a URL, for use as a CSP source.withContentSecurityPolicyEnabled(boolean enabled) Send the Content-Security-Policy (default) or not at all.withDirective(String directive, String... sources) Replace a directive's sources (for example withDirective("frame-ancestors", "'self'") to allow same-origin framing).withHeader(String name, String value) Set a response header sent with every dashboard file, or remove it.withoutDirective(String directive) Remove a directive from the policy.withoutSources(String directive, String... sources) Remove sources from a directive.withReportOnly(boolean reportOnly) Send the policy as Content-Security-Policy-Report-Only, for trying out a changed policy without enforcing it.withSources(String directive, String... sources) Add sources to a directive, creating it when absent.
-
Field Details
-
CONTENT_SECURITY_POLICY
- See Also:
-
CONTENT_SECURITY_POLICY_REPORT_ONLY
- See Also:
-
X_FRAME_OPTIONS
- See Also:
-
REFERRER_POLICY
- See Also:
-
PERMISSIONS_POLICY
- See Also:
-
X_CONTENT_TYPE_OPTIONS
- See Also:
-
SCRIPT_SRC
- See Also:
-
DEFAULT_PERMISSIONS_POLICY
-
-
Constructor Details
-
NextDashboardSecurityHeaders
public NextDashboardSecurityHeaders()The default (strict) policy and headers.
-
-
Method Details
-
originOf
-
withDirective
Replace a directive's sources (for example withDirective("frame-ancestors", "'self'") to allow same-origin framing).- Parameters:
directive- CSP directive name, lowercasesources- source expressions; none gives a directive without sources- Returns:
- this
-
withSources
Add sources to a directive, creating it when absent.- Parameters:
directive- CSP directive name, lowercasesources- source expressions to append (duplicates are ignored)- Returns:
- this
-
withoutSources
Remove sources from a directive.- Parameters:
directive- CSP directive name, lowercasesources- source expressions to remove- Returns:
- this
-
withoutDirective
Remove a directive from the policy.- Parameters:
directive- CSP directive name, lowercase- Returns:
- this
-
withHeader
Set a response header sent with every dashboard file, or remove it.- Parameters:
name- header name, such as Referrer-Policyvalue- the value, or null to not send the header- Returns:
- this
-
withContentSecurityPolicyEnabled
Send the Content-Security-Policy (default) or not at all.- Parameters:
enabled- false to send no policy- Returns:
- this
-
withReportOnly
Send the policy as Content-Security-Policy-Report-Only, for trying out a changed policy without enforcing it.- Parameters:
reportOnly- true to report violations instead of blocking- Returns:
- this
-
getSources
-
getHeaders
-
getContentSecurityPolicyHeaderName
Name of the policy header: Content-Security-Policy, the report-only variant, or null when the policy is disabled. -
buildContentSecurityPolicy
The policy for one document, with the hashes of its inline scripts added to script-src.- Parameters:
scriptHashes- source expressions such as 'sha256-...'- Returns:
- the header value
-