lukaszlenart commented on a change in pull request #426:
URL: https://github.com/apache/struts/pull/426#discussion_r454244077
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/DefaultResourceIsolationPolicy.java
##########
@@ -0,0 +1,49 @@
+package org.apache.struts2.interceptor;
Review comment:
You are missing a header with license, see other files for an example
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/DefaultResourceIsolationPolicy.java
##########
@@ -0,0 +1,49 @@
+package org.apache.struts2.interceptor;
+
+import org.apache.logging.log4j.util.Strings;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * Default resource isolation policy used in {@link FetchMetadataInterceptor}
that
+ * implements the {@link ResourceIsolationPolicy} interface. This default
policy is based on
+ * <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>.
+ *
+ * @see <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>
+ *
+ * @author Santiago Diaz - [email protected]
+ * @author Giannis Chatziveroglou - [email protected]
Review comment:
Please remove these tags and emails, after merging this code it will be
owned by ASF and you want to be bothered by users to help them resolve their
problems, it's community duty :)
http://tinyurl.com/mw7t6
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/ResourceIsolationPolicy.java
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.interceptor;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Interface for the resource isolation policies to be used for fetch metadata
checks.
+ *
+ * Resource isolation policies are designed to protect against cross origin
attacks and use the
+ * {@code sec-fetch-*} request headers to decide whether to accept or reject a
request. Read more
+ * about <a href="https://web.dev/fetch-metadata/">Fetch Metadata.</a>
+ *
+ * See {@link DefaultResourceIsolationPolicy} for the default implementation
used.
+ *
+ * @see <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>
+ *
+ * @author Santiago Diaz - [email protected]
+ * @author Giannis Chatziveroglou - [email protected]
Review comment:
Please remove these tags as explained earlier
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/DefaultResourceIsolationPolicy.java
##########
@@ -0,0 +1,49 @@
+package org.apache.struts2.interceptor;
+
+import org.apache.logging.log4j.util.Strings;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * Default resource isolation policy used in {@link FetchMetadataInterceptor}
that
+ * implements the {@link ResourceIsolationPolicy} interface. This default
policy is based on
+ * <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>.
+ *
+ * @see <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>
+ *
+ * @author Santiago Diaz - [email protected]
+ * @author Giannis Chatziveroglou - [email protected]
+ **/
+
+public final class DefaultResourceIsolationPolicy implements
ResourceIsolationPolicy {
Review comment:
```suggestion
public final class StrutsResourceIsolationPolicy implements
ResourceIsolationPolicy {
```
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/FetchMetadataInterceptor.java
##########
@@ -0,0 +1,96 @@
+package org.apache.struts2.interceptor;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+import com.opensymphony.xwork2.interceptor.PreResultListener;
+import com.opensymphony.xwork2.util.TextParseUtil;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * <!-- START SNIPPET: description -->
Review comment:
It's not needed anymore, we don't use Confluence any longer, instead
you can create a PR with description about the new interceptor
[here](https://github.com/apache/struts-site/blob/master/source/core-developers/interceptors.md)
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/FetchMetadataInterceptor.java
##########
@@ -0,0 +1,96 @@
+package org.apache.struts2.interceptor;
Review comment:
Header with a license is missing
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/DefaultResourceIsolationPolicy.java
##########
@@ -0,0 +1,49 @@
+package org.apache.struts2.interceptor;
+
+import org.apache.logging.log4j.util.Strings;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * Default resource isolation policy used in {@link FetchMetadataInterceptor}
that
+ * implements the {@link ResourceIsolationPolicy} interface. This default
policy is based on
+ * <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>.
+ *
+ * @see <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>
+ *
+ * @author Santiago Diaz - [email protected]
+ * @author Giannis Chatziveroglou - [email protected]
+ **/
+
+public final class DefaultResourceIsolationPolicy implements
ResourceIsolationPolicy {
+
+ @Override
+ public boolean isRequestAllowed(HttpServletRequest request) {
+ String site = request.getHeader(SEC_FETCH_SITE_HEADER);
+
+ // Allow requests from browsers which don't send Fetch Metadata
+ if (Strings.isEmpty((site))){
+ return true;
+ }
+
+ // Allow same-site and browser-initiated requests
+ if (SAME_ORIGIN.equals(site) || SAME_SITE.equals(site) ||
NONE.equals(site)) {
+ return true;
+ }
+
+ // Allow simple top-level navigations except <object> and <embed>
+ return isAllowedTopLevelNavigation(request);
+ }
+
+ private boolean isAllowedTopLevelNavigation(HttpServletRequest request)
+ {
Review comment:
Inconsistent formatting, please move this bracket to the end of the
previous line, thanks!
##########
File path:
core/src/main/java/org/apache/struts2/interceptor/DefaultResourceIsolationPolicy.java
##########
@@ -0,0 +1,49 @@
+package org.apache.struts2.interceptor;
+
+import org.apache.logging.log4j.util.Strings;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * Default resource isolation policy used in {@link FetchMetadataInterceptor}
that
+ * implements the {@link ResourceIsolationPolicy} interface. This default
policy is based on
+ * <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>.
+ *
+ * @see <a
href="https://web.dev/fetch-metadata/">https://web.dev/fetch-metadata/</a>
+ *
+ * @author Santiago Diaz - [email protected]
+ * @author Giannis Chatziveroglou - [email protected]
+ **/
+
+public final class DefaultResourceIsolationPolicy implements
ResourceIsolationPolicy {
Review comment:
I prefer to use `Struts` prefix to indicate that this a default `Struts`
implementation :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]