Class ContentSecurityPolicyViolationReporter
new Function and a strict Content
Security Policy without unsafe-eval blocks.
What happens depends on the ContentSecurityPolicyMode of the current
service: nothing in ContentSecurityPolicyMode.OFF, a warning logged
once per call site and detail in ContentSecurityPolicyMode.WARN, and
a ContentSecurityPolicyViolationException in
ContentSecurityPolicyMode.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 itsContentSecurityPolicyModeisContentSecurityPolicyMode.WARNorContentSecurityPolicyMode.STRICT.static voidreportStringDynamicImport(String expression) Reports a dynamic import given as a string expression.static voidreportStringEventData(List<String> eventData) Reports event data values given as string expressions.static voidreportStringExecuteJs(String expression, int parameterCount) Reports a call toexecuteJswith a string expression.static voidreportStringFilter(String filter) Reports an event filter given as a string expression.static voidreportStringFunction(String body, int captureCount) Reports a function created from a string body, asJsFunction.ofand the stringaddJsInitializerdo.static voidreportStringFunction(String body, int captureCount, List<String> argumentNames) Reports a function created from a string body that is then given the names of its runtime arguments withJsFunction.withArguments.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:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.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:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
reportStringExecuteJs
Reports a call toexecuteJswith a string expression. Called by the API itself, which is where the stack trace of the report starts.The message adds a declared method for the expression, ready to paste, and says how to use it: called through
executeJs(Class)when the call is in code the developer can change, or in an interface marked withJsStringFallbackwhen it is in an add-on that the developer can not change. A warning is logged once per call site and expression, so a call site that sends different strings, such as one that concatenates values into them, is reported for each of them.- Parameters:
expression- the expression that is sent, notnullparameterCount- the number of parameters the expression is sent with- Throws:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
reportStringFunction
Reports a function created from a string body, asJsFunction.ofand the stringaddJsInitializerdo. Called by the API itself, which is where the stack trace of the report starts.Like
reportStringExecuteJs(String, int), the message adds the declared method for the body and says how to use it.- Parameters:
body- the body of the function, notnullcaptureCount- the number of values the function captures- Throws:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
reportStringFunction
Reports a function created from a string body that is then given the names of its runtime arguments withJsFunction.withArguments. Called by the API itself, which is where the stack trace of the report starts.Like
reportStringFunction(String, int), the message adds the declared method for the body, here with the names in@JsFunctionParameterNames.- Parameters:
body- the body of the function, notnullcaptureCount- the number of values the function capturesargumentNames- the names of the runtime arguments, notnull- Throws:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
reportStringDynamicImport
Reports a dynamic import given as a string expression. Called by the API itself, which is where the stack trace of the report starts.Like
reportStringExecuteJs(String, int), the message adds the declared method for the expression and says how to use it.- Parameters:
expression- the expression that returns aPromise, notnull- Throws:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
reportStringFilter
Reports an event filter given as a string expression. Called by the API itself, which is where the stack trace of the report starts.The message says how to declare the filter: as a filter snippet when the call is in code the developer can change, or in
JsStringFallback.filters()when it is in an add-on.- Parameters:
filter- the filter, notnull- Throws:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
reportStringEventData
Reports event data values given as string expressions. Called by the API itself, which is where the stack trace of the report starts.The message says how to declare the values: as event data snippets when the call is in code the developer can change, or in
JsStringFallback.eventData()when it is in an add-on.- Parameters:
eventData- the values the browser would compile, possibly mapped to an element, notnulland not empty- Throws:
ContentSecurityPolicyViolationException- in theContentSecurityPolicyMode.STRICTmode
-
isEnabled
public static boolean isEnabled()Checks whether string JavaScript is reported for the current service, i.e. whether itsContentSecurityPolicyModeisContentSecurityPolicyMode.WARNorContentSecurityPolicyMode.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
-