github-advanced-security[bot] commented on code in PR #17577:
URL: 
https://github.com/apache/dolphinscheduler/pull/17577#discussion_r2480486871


##########
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/config/ActuatorSecurityConfig.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.common.config;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import 
org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import 
org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import 
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+
+/**
+ * Security configuration for Actuator endpoints.
+ * <p>
+ * This configuration applies security rules to Actuator paths such as:
+ * <ul>
+ *   <li>/actuator/</li>
+ *   <li>/dolphinscheduler/actuator/</li>
+ * </ul>
+ * Security can be enabled/disabled via {@code management.security.enabled}.
+ * When enabled, HTTP Basic authentication is required with a configured 
username and password.
+ * </p>
+ */
+@Configuration
+@EnableWebSecurity
+@EnableConfigurationProperties(ActuatorSecurityConfig.ActuatorSecurityProperties.class)
+public class ActuatorSecurityConfig {
+
+    private static final String ACTUATOR_PATH_PATTERN_1 = 
"/dolphinscheduler/actuator/";
+    private static final String ACTUATOR_PATH_PATTERN_2 = "/actuator/";
+    private static final String ROLE_ACTUATOR = "ACTUATOR";
+
+    @Bean
+    public SecurityFilterChain actuatorSecurityFilterChain(
+                                                           HttpSecurity http,
+                                                           
ActuatorSecurityProperties properties) throws Exception {
+
+        // Restrict this security configuration to requests starting with 
actuator paths
+        http.requestMatcher(request -> 
request.getRequestURI().startsWith(ACTUATOR_PATH_PATTERN_1) ||
+                request.getRequestURI().startsWith(ACTUATOR_PATH_PATTERN_2));
+
+        if (properties.isEnabled()) {
+            http.authorizeHttpRequests(authz -> {
+                // Grant public access to endpoints listed in exclude
+                for (String endpoint : properties.getExclude()) {
+                    if (StringUtils.isNotBlank(endpoint)) {
+                        String cleanEndpoint = endpoint.trim();
+                        // Match both standard and prefixed actuator paths
+                        authz.requestMatchers(
+                                new 
AntPathRequestMatcher(ACTUATOR_PATH_PATTERN_2 + cleanEndpoint)).permitAll();
+                        authz.requestMatchers(
+                                new 
AntPathRequestMatcher(ACTUATOR_PATH_PATTERN_1 + cleanEndpoint)).permitAll();
+                    }
+                }
+                // All other actuator requests require the ACTUATOR role
+                authz.anyRequest().hasRole(ROLE_ACTUATOR);
+            })
+                    .httpBasic(); // Use HTTP Basic authentication for secured 
endpoints
+        } else {
+            // If security is disabled, allow all requests to actuator 
endpoints
+            http.authorizeHttpRequests(authz -> 
authz.anyRequest().permitAll());
+        }
+
+        // Disable CSRF for actuator endpoints as they are typically accessed 
by scripts or monitoring tools
+        http.csrf().disable();

Review Comment:
   ## Disabled Spring CSRF protection
   
   CSRF vulnerability due to protection being disabled.
   
   [Show more 
details](https://github.com/apache/dolphinscheduler/security/code-scanning/5576)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to