[
https://issues.apache.org/jira/browse/WW-5400?focusedWorklogId=922275&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-922275
]
ASF GitHub Bot logged work on WW-5400:
--------------------------------------
Author: ASF GitHub Bot
Created on: 06/Jun/24 03:54
Start Date: 06/Jun/24 03:54
Worklog Time Spent: 10m
Work Description: kusalk commented on code in PR #956:
URL: https://github.com/apache/struts/pull/956#discussion_r1628741666
##########
core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java:
##########
@@ -57,26 +59,28 @@ public String intercept(ActionInvocation invocation) throws
Exception {
LOG.trace("Using CspSettings provided by the action: {}", action);
applySettings(invocation, ((CspSettingsAware)
action).getCspSettings());
} else {
- LOG.trace("Using {} with action: {}", defaultCspSettingsClassName,
action);
+ LOG.trace("Using {} with action: {}", cspSettingsClassName,
action);
+ CspSettings cspSettings = createCspSettings(invocation);
+ applySettings(invocation, cspSettings);
+ }
+ return invocation.invoke();
+ }
- // if the defaultCspSettingsClassName is not a real class, throw
an exception
- try {
- Class.forName(defaultCspSettingsClassName, false,
Thread.currentThread().getContextClassLoader());
- }
- catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("The
defaultCspSettingsClassName must be a real class.");
- }
+ private CspSettings createCspSettings(ActionInvocation invocation) throws
ClassNotFoundException {
+ Class<?> cspSettingsClass;
- // if defaultCspSettingsClassName does not implement CspSettings,
throw an exception
- if
(!CspSettings.class.isAssignableFrom(Class.forName(defaultCspSettingsClassName)))
{
- throw new IllegalArgumentException("The
defaultCspSettingsClassName must implement CspSettings.");
- }
+ try {
+ cspSettingsClass = ClassLoaderUtil.loadClass(cspSettingsClassName,
getClass());
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException(String.format("The class %s
doesn't exist!", cspSettingsClassName));
+ }
- CspSettings cspSettings = (CspSettings)
Class.forName(defaultCspSettingsClassName)
- .getDeclaredConstructor().newInstance();
- applySettings(invocation, cspSettings);
+ if
(!CspSettings.class.isAssignableFrom(Class.forName(cspSettingsClassName))) {
Review Comment:
```suggestion
if (!CspSettings.class.isAssignableFrom(cspSettingsClass)) {
```
Issue Time Tracking
-------------------
Worklog Id: (was: 922275)
Time Spent: 2h 20m (was: 2h 10m)
> CSP interceptor only allows very limited configuration
> ------------------------------------------------------
>
> Key: WW-5400
> URL: https://issues.apache.org/jira/browse/WW-5400
> Project: Struts 2
> Issue Type: Improvement
> Components: Core Interceptors
> Affects Versions: 6.3.0
> Reporter: Erica Kane
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 6.5.0
>
> Time Spent: 2h 20m
> Remaining Estimate: 0h
>
> I have been trying to implement CSP on our website. The CSP interceptor
> provides an elegant solution with the <s:script> and <s:link> tags. However,
> I want to set my own base-uri. And perhaps make some other changes to the CSP
> headers.
> But these values are not accessible. Only the report-only and report-uri can
> be changed. Even if one is willing to work at the Action level and implement
> a new interface for all of them, I can't change the base-uri. I've seen
> people on Stack Overflow disable it for this reason. I want to use it, but
> could someone please explain how to set the base-uri globally? If not, I will
> likely have to make my own.
> P.S. I will update the documentation page. Nowhere in the description of the
> interceptor does it mention the script and link tags, and without those, it
> is useless!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)