You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/12/20 16:22:21 UTC

[GitHub] [dolphinscheduler] github-code-scanning[bot] commented on a diff in pull request #13235: [Improvement][Security]Add CSRF protection using spring security(issue-12931)

github-code-scanning[bot] commented on code in PR #13235:
URL: https://github.com/apache/dolphinscheduler/pull/13235#discussion_r1053506083


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/LoginCsrfTokenRepository.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.dolphinscheduler.api.security;
+
+import org.apache.dolphinscheduler.api.controller.LoginController;
+
+import java.util.UUID;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.security.web.csrf.CsrfToken;
+import org.springframework.security.web.csrf.CsrfTokenRepository;
+import org.springframework.security.web.csrf.DefaultCsrfToken;
+import org.springframework.util.StringUtils;
+import org.springframework.web.util.WebUtils;
+
+public final class LoginCsrfTokenRepository implements CsrfTokenRepository {
+
+    public static final String PARAMETER_NAME = "_csrf";
+    public static final String HEADER_NAME = "X-XSRF-TOKEN";
+    public static final String COOKIE_NAME = "csrfToken";
+
+    public LoginCsrfTokenRepository() {
+    }
+
+    /**
+     * The csrf token will be generated in {@link CsrfFilter}
+     * @param request http servlet request
+     */
+    public CsrfToken generateToken(HttpServletRequest request) {
+        return new DefaultCsrfToken(HEADER_NAME, PARAMETER_NAME, createNewToken());
+    }
+
+    /**
+     * The csrf token will be stored in the http request so that the login api {@link LoginController} can obtain the csrf token
+     * @param token csrf token generated in {@link CsrfFilter}
+     * @param request http servlet request
+     * @param response http servlet response
+     */
+    public void saveToken(CsrfToken token, HttpServletRequest request, HttpServletResponse response) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [CsrfTokenRepository.saveToken](1); it is advisable to add an Override annotation.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/2402)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/LoginCsrfTokenRepository.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.dolphinscheduler.api.security;
+
+import org.apache.dolphinscheduler.api.controller.LoginController;
+
+import java.util.UUID;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.security.web.csrf.CsrfToken;
+import org.springframework.security.web.csrf.CsrfTokenRepository;
+import org.springframework.security.web.csrf.DefaultCsrfToken;
+import org.springframework.util.StringUtils;
+import org.springframework.web.util.WebUtils;
+
+public final class LoginCsrfTokenRepository implements CsrfTokenRepository {
+
+    public static final String PARAMETER_NAME = "_csrf";
+    public static final String HEADER_NAME = "X-XSRF-TOKEN";
+    public static final String COOKIE_NAME = "csrfToken";
+
+    public LoginCsrfTokenRepository() {
+    }
+
+    /**
+     * The csrf token will be generated in {@link CsrfFilter}
+     * @param request http servlet request
+     */
+    public CsrfToken generateToken(HttpServletRequest request) {
+        return new DefaultCsrfToken(HEADER_NAME, PARAMETER_NAME, createNewToken());
+    }
+
+    /**
+     * The csrf token will be stored in the http request so that the login api {@link LoginController} can obtain the csrf token
+     * @param token csrf token generated in {@link CsrfFilter}
+     * @param request http servlet request
+     * @param response http servlet response
+     */
+    public void saveToken(CsrfToken token, HttpServletRequest request, HttpServletResponse response) {
+
+    }
+
+    /**
+     * load csrf token from http request cookie
+     * @param request http servlet request
+     * @return csrf token
+     */
+    public CsrfToken loadToken(HttpServletRequest request) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [CsrfTokenRepository.loadToken](1); it is advisable to add an Override annotation.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/2401)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/security/LoginCsrfTokenRepository.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.dolphinscheduler.api.security;
+
+import org.apache.dolphinscheduler.api.controller.LoginController;
+
+import java.util.UUID;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.security.web.csrf.CsrfFilter;
+import org.springframework.security.web.csrf.CsrfToken;
+import org.springframework.security.web.csrf.CsrfTokenRepository;
+import org.springframework.security.web.csrf.DefaultCsrfToken;
+import org.springframework.util.StringUtils;
+import org.springframework.web.util.WebUtils;
+
+public final class LoginCsrfTokenRepository implements CsrfTokenRepository {
+
+    public static final String PARAMETER_NAME = "_csrf";
+    public static final String HEADER_NAME = "X-XSRF-TOKEN";
+    public static final String COOKIE_NAME = "csrfToken";
+
+    public LoginCsrfTokenRepository() {
+    }
+
+    /**
+     * The csrf token will be generated in {@link CsrfFilter}
+     * @param request http servlet request
+     */
+    public CsrfToken generateToken(HttpServletRequest request) {

Review Comment:
   ## Missing Override annotation
   
   This method overrides [CsrfTokenRepository.generateToken](1); it is advisable to add an Override annotation.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/2403)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org