skoppu22 commented on code in PR #369:
URL: https://github.com/apache/cassandra-sidecar/pull/369#discussion_r3544634146


##########
server/src/main/java/org/apache/cassandra/sidecar/configmanagement/ConfigurationPatchValidator.java:
##########
@@ -0,0 +1,283 @@
+/*
+ * 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.cassandra.sidecar.configmanagement;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Validates a list of {@link ConfigurationPatchOperation} instances before 
application.
+ *
+ * <p>Validation includes:
+ * <ul>
+ *   <li>Path format: must start with {@code /configuration/cassandraYaml/} or
+ *       {@code /configuration/extraJvmOpts/}</li>
+ *   <li>Value presence: required for add/replace/test, must be absent for 
remove</li>
+ *   <li>Duplicate path detection: multiple mutation ops targeting the same 
path are rejected</li>
+ *   <li>Path segments split by {@code /}; empty segments are rejected</li>
+ * </ul>
+ */
+public final class ConfigurationPatchValidator
+{
+    static final String PATH_PREFIX = "/configuration/";
+    static final String CASSANDRA_YAML_SECTION = "cassandraYaml";
+    static final String EXTRA_JVM_OPTS_SECTION = "extraJvmOpts";
+    static final String CASSANDRA_YAML_PREFIX = PATH_PREFIX + 
CASSANDRA_YAML_SECTION + "/";
+    static final String EXTRA_JVM_OPTS_PREFIX = PATH_PREFIX + 
EXTRA_JVM_OPTS_SECTION + "/";
+
+    // Allows: -Dproperty.name, -Xmx, -Xss, -XX:+Flag, -XX:-Flag, -XX:Flag
+    // Rejects: -javaagent, -agentpath, -agentlib, keys with = or shell 
metacharacters
+    static final Pattern JVM_OPT_KEY_PATTERN = Pattern.compile(
+            
"^-(D[a-zA-Z][a-zA-Z0-9._-]*|X[a-z][a-zA-Z0-9]*|XX:[+-]?[a-zA-Z][a-zA-Z0-9_]*)$");
+
+    // XX flags that accept arbitrary commands as values
+    static final Set<String> BLOCKED_XX_FLAGS = Set.of(

Review Comment:
   There are more options which can take paths etc e.g. -XX:ErrorFile, 
-XX:HeapDumpPath, -XX:LogFile, -Xloggc, and -D-style system properties. All 
absolute paths are allowed. Good to have allowlist instead of blocklist to be 
specific about which options are allowed and which paths are allowed.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to