Class CspViolationReporter
new Function and a strict Content
Security Policy without unsafe-eval blocks.
What happens depends on the CspMode of the current service: nothing
in CspMode.OFF, a warning logged once per call site and detail in
CspMode.WARN, and a CspViolationException in
CspMode.STRICT. Every string-based call is reported, including the
ones that Vaadin itself makes. Both the warning and the exception carry a
stack trace that starts at the API and leads to the code that called it.
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.4
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether string JavaScript is reported for the current service, i.e. whether itsCspModeisCspMode.WARNorCspMode.STRICT.static voidReports a call to an API that sends JavaScript to the browser as a string.static voidreportStringJavaScript(String detail) Reports a call to an API that sends JavaScript to the browser as a string, with a detail that tells what is reported.
-
Method Details
-
reportStringJavaScript
public static void reportStringJavaScript()Reports a call to an API that sends JavaScript to the browser as a string. Called by the API itself, which is where the stack trace of the report starts.A warning is logged once per call site. Use
reportStringJavaScript(String)when the call site does not tell what is reported, e.g. when a component reports from an action that runs before the client response.- Throws:
CspViolationException- in theCspMode.STRICTmode
-
reportStringJavaScript
Reports a call to an API that sends JavaScript to the browser as a string, with a detail that tells what is reported. Called by the API itself, which is where the stack trace of the report starts.The detail is added to the message, and a warning is logged once per call site and detail. This identifies the report when the call site alone does not, e.g. when a component reports from an action that runs before the client response, where the stack does not reach the application code that set the JavaScript. Use
reportStringJavaScript()when the call site is enough.- Parameters:
detail- a short description of what is reported, e.g. the path of the option that has the JavaScript, notnull- Throws:
CspViolationException- in theCspMode.STRICTmode
-
isEnabled
public static boolean isEnabled()Checks whether string JavaScript is reported for the current service, i.e. whether itsCspModeisCspMode.WARNorCspMode.STRICT. A caller that does extra work to collect what it reports, e.g. to find the detail forreportStringJavaScript(String), can skip that work when this returnsfalse.- Returns:
trueif reports are logged or thrown,falseif they are ignored
-