Copilot commented on code in PR #12445:
URL: https://github.com/apache/apisix/pull/12445#discussion_r2734667915


##########
apisix/discovery/nacos/init.lua:
##########
@@ -21,7 +21,9 @@ local http               = require('resty.http')
 local core               = require('apisix.core')
 local ipairs             = ipairs
 local pairs              = pairs
+local next               = next
 local type               = type
+local math               = math

Review Comment:
   The local variable 'math' on line 26 is not used anywhere in the code. It's 
only needed on line 27 to extract 'math.random' into the 'math_random' 
variable. Since 'math' is a built-in Lua global, it doesn't need to be cached 
unless it's used multiple times. Consider removing line 26 as it's redundant.
   ```suggestion
   
   ```



##########
ci/pod/nacos/service/entrypoint.sh:
##########
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# 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.
+#
+
+# Build Java command with proper environment variable expansion
+JAVA_ARGS=(
+    "-Djava.security.egd=file:/dev/./urandom"
+    "-jar"
+    "/app.jar"
+    "--suffix.num=${SUFFIX_NUM}"
+    "--spring.cloud.nacos.discovery.server-addr=${NACOS_ADDR}"
+    "--spring.application.name=${SERVICE_NAME}"
+    "--spring.cloud.nacos.discovery.group=${GROUP}"
+    "--spring.cloud.nacos.discovery.namespace=${NAMESPACE}"
+)
+
+# Add metadata dynamically for all METADATA_* environment variables
+for var in $(env | grep '^METADATA_' | cut -d= -f1); do
+    # Convert METADATA_LANE to lane, METADATA_ENV to env, etc.
+    metadata_key=$(echo "${var#METADATA_}" | tr '[:upper:]' '[:lower:]')
+    metadata_value=$(eval echo \$${var})

Review Comment:
   The use of `eval` on environment-derived values in `metadata_value=$(eval 
echo \$${var})` allows arbitrary shell command injection if a `METADATA_*` 
environment variable contains shell metacharacters or command substitutions. An 
attacker who can set these environment variables for this container can execute 
arbitrary commands in the container context when the entrypoint runs. Avoid 
using `eval` and unquoted expansions here; instead, read the environment 
variable value via safe parameter expansion without re-interpreting its 
contents as shell code.
   ```suggestion
       metadata_value=${!var}
   ```



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