Skip to content

Commit cef3e86

Browse files
tenpercentclaude
andcommitted
Fix command injection and path traversal vulnerabilities
Security fixes: 1. Command Injection Prevention - Use docker exec -e flag to pass variables as environment variables - Change bash -c to use single quotes to prevent shell expansion - Properly quote all variables within the single-quoted commands - Affects: CMAKE configuration, ninja build, trace file search, Python analysis 2. Path Traversal Protection for OUTPUT_FILE - Validate OUTPUT_FILE contains no path separators (/) - Validate OUTPUT_FILE contains no parent directory references (..) - Allows file extensions (.md) but blocks directory traversal - Prevents writing files outside project directory Tested: - ✅ Path traversal blocked: --output="../../../tmp/evil.md" - ✅ Double-dot blocked: --output="..evil.md" - ✅ Normal operation: --output="security_test.md" - ✅ Build process works with quoted variables Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 28489b0 commit cef3e86

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

.claude/skills/ck-build-analysis

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ if [ -z "$TARGET" ]; then
9595
exit 1
9696
fi
9797

98+
# Validate OUTPUT_FILE to prevent path traversal
99+
if [[ "$OUTPUT_FILE" =~ / ]] || [[ "$OUTPUT_FILE" =~ \.\. ]]; then
100+
echo "Error: OUTPUT_FILE must be a simple filename (no path separators or .. allowed)"
101+
echo "Invalid: $OUTPUT_FILE"
102+
exit 1
103+
fi
104+
98105
echo "═══════════════════════════════════════════════════════════════"
99106
echo " CK Build Time Analysis"
100107
echo "═══════════════════════════════════════════════════════════════"
@@ -115,19 +122,19 @@ if [ "$RECONFIGURE" = true ] || ! docker exec "${CONTAINER_NAME}" test -f /works
115122

116123
GPU_TARGET=$(detect_gpu_target "${CONTAINER_NAME}")
117124

118-
docker exec "${CONTAINER_NAME}" bash -c "
125+
docker exec -e GPU_TARGET="${GPU_TARGET}" -e GRANULARITY="${GRANULARITY}" "${CONTAINER_NAME}" bash -c '
119126
cd /workspace || exit 1
120127
rm -rf /workspace/build
121128
mkdir /workspace/build
122129
cd /workspace/build || exit 1
123130
cmake .. -GNinja \
124-
-DGPU_TARGETS=${GPU_TARGET} \
131+
-DGPU_TARGETS="${GPU_TARGET}" \
125132
-DCMAKE_BUILD_TYPE=Release \
126133
-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \
127-
-DCMAKE_CXX_FLAGS='-ftime-trace -ftime-trace-granularity=${GRANULARITY}' \
128-
-DCMAKE_HIP_FLAGS='-ftime-trace -ftime-trace-granularity=${GRANULARITY}' \
134+
-DCMAKE_CXX_FLAGS="-ftime-trace -ftime-trace-granularity=${GRANULARITY}" \
135+
-DCMAKE_HIP_FLAGS="-ftime-trace -ftime-trace-granularity=${GRANULARITY}" \
129136
-DBUILD_TESTING=ON 2>&1 | tail -20
130-
"
137+
'
131138
echo "CMake configuration complete"
132139
fi
133140

@@ -137,7 +144,7 @@ echo "Building target: $TARGET"
137144
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
138145

139146
BUILD_START=$(date +%s)
140-
docker exec "${CONTAINER_NAME}" bash -c "cd /workspace/build && time ninja ${TARGET} 2>&1"
147+
docker exec -e TARGET="${TARGET}" "${CONTAINER_NAME}" bash -c 'cd /workspace/build && time ninja "${TARGET}" 2>&1'
141148
BUILD_END=$(date +%s)
142149
BUILD_TIME=$((BUILD_END - BUILD_START))
143150

@@ -147,7 +154,7 @@ echo "Build completed in ${BUILD_TIME} seconds"
147154
# Find the trace JSON file
148155
echo ""
149156
echo "Locating trace file..."
150-
TRACE_FILE=$(docker exec "${CONTAINER_NAME}" bash -c "find /workspace/build -name '*.cpp.json' -o -name '*.hip.json' 2>/dev/null | grep -i '${TARGET}' | head -1")
157+
TRACE_FILE=$(docker exec -e TARGET="${TARGET}" "${CONTAINER_NAME}" bash -c 'find /workspace/build -name "*.cpp.json" -o -name "*.hip.json" 2>/dev/null | grep -iF "${TARGET}" | head -1')
151158

152159
if [ -z "$TRACE_FILE" ]; then
153160
echo "Error: Could not find trace file for target ${TARGET}"
@@ -182,13 +189,7 @@ fi
182189

183190
echo "Using uv run for automatic dependency management..."
184191
# Ensure uv is in PATH (handles ~/.local/bin installation)
185-
docker exec "${CONTAINER_NAME}" bash -c "export PATH=\"\$HOME/.local/bin:\$PATH\" && uv run --no-project /tmp/analyze_build_trace.py \
186-
${TRACE_FILE} \
187-
/workspace/${OUTPUT_FILE} \
188-
${TARGET} \
189-
${GRANULARITY} \
190-
${BUILD_TIME} \
191-
/tmp/ck_build_analysis_templates"
192+
docker exec -e TRACE_FILE="${TRACE_FILE}" -e OUTPUT_FILE="${OUTPUT_FILE}" -e TARGET="${TARGET}" -e GRANULARITY="${GRANULARITY}" -e BUILD_TIME="${BUILD_TIME}" "${CONTAINER_NAME}" bash -c 'export PATH="$HOME/.local/bin:$PATH" && uv run --no-project /tmp/analyze_build_trace.py "${TRACE_FILE}" "/workspace/${OUTPUT_FILE}" "${TARGET}" "${GRANULARITY}" "${BUILD_TIME}" /tmp/ck_build_analysis_templates'
192193

193194
# Copy report back to host
194195
docker cp "${CONTAINER_NAME}:/workspace/${OUTPUT_FILE}" "${PROJECT_ROOT}/${OUTPUT_FILE}"

0 commit comments

Comments
 (0)