Skip to content

Commit 4395794

Browse files
committed
Update security scan scripts to suppress error output
- Modified various security scan scripts (e.g., run_anchore.sh, run_bandit.sh, run_burp.sh) to redirect error output to /dev/null, improving log cleanliness. - Ensured that failure messages are still logged to the main log file for transparency while reducing clutter from error messages during report generation. - This change enhances the user experience by focusing on successful operations and critical failures only.
1 parent 576f975 commit 4395794

25 files changed

Lines changed: 58 additions & 58 deletions

scripts/tools/run_anchore.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ if command -v grype &>/dev/null; then
2929
# Run Anchore Grype scan on container image
3030
echo "[run_anchore.sh][Anchore] Running container image vulnerability scan..." | tee -a "$LOG_FILE"
3131

32-
grype --config "$ANCHORE_CONFIG_PATH" --output json "$ANCHORE_IMAGE" > "$ANCHORE_JSON" 2>>"$LOG_FILE" || {
32+
grype --config "$ANCHORE_CONFIG_PATH" --output json "$ANCHORE_IMAGE" > "$ANCHORE_JSON" 2>/dev/null || {
3333
echo "[run_anchore.sh][Anchore] Scan failed, continuing..." | tee -a "$LOG_FILE"
3434
}
3535

3636
# Generate text output
37-
grype --config "$ANCHORE_CONFIG_PATH" "$ANCHORE_IMAGE" > "$ANCHORE_TEXT" 2>>"$LOG_FILE" || {
37+
grype --config "$ANCHORE_CONFIG_PATH" "$ANCHORE_IMAGE" > "$ANCHORE_TEXT" 2>/dev/null || {
3838
echo "[run_anchore.sh][Anchore] Text output generation failed, continuing..." | tee -a "$LOG_FILE"
3939
}
4040

scripts/tools/run_bandit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ if command -v bandit &>/dev/null; then
4040
echo "[run_bandit.sh][Bandit] Found $PYTHON_FILES Python file(s) to scan..." | tee -a "$LOG_FILE"
4141

4242
# Run Bandit scan with JSON output
43-
bandit -r "$TARGET_PATH" -f json -o "$BANDIT_JSON" 2>>"$LOG_FILE" || {
43+
bandit -r "$TARGET_PATH" -f json -o "$BANDIT_JSON" 2>/dev/null || {
4444
echo "[run_bandit.sh][Bandit] JSON report generation encountered issues." >> "$LOG_FILE"
4545
}
4646

4747
# Run Bandit scan with text output
48-
bandit -r "$TARGET_PATH" > "$BANDIT_TEXT" 2>>"$LOG_FILE" || {
48+
bandit -r "$TARGET_PATH" > "$BANDIT_TEXT" 2>/dev/null || {
4949
echo "[run_bandit.sh][Bandit] Text report generation encountered issues." >> "$LOG_FILE"
5050
}
5151

scripts/tools/run_brakeman.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ if command -v brakeman &>/dev/null; then
4141
echo "[run_brakeman.sh][Brakeman] Found ${#RUBY_FILES[@]} Ruby/Rails file(s)." | tee -a "$LOG_FILE"
4242

4343
# Generate JSON report with --force to scan anyway
44-
if brakeman -q -f json -o "$BRAKEMAN_JSON" --force "$TARGET_PATH" 2>>"$LOG_FILE"; then
44+
if brakeman -q -f json -o "$BRAKEMAN_JSON" --force "$TARGET_PATH" 2>/dev/null; then
4545
echo "[run_brakeman.sh][Brakeman] JSON report generation completed." | tee -a "$LOG_FILE"
4646
else
4747
echo "[run_brakeman.sh][Brakeman] JSON report generation failed." >> "$LOG_FILE"
4848
fi
4949

5050
# Generate text report (without format option, outputs plaintext by default) with --force
51-
if brakeman -q -o "$BRAKEMAN_TEXT" --force "$TARGET_PATH" 2>>"$LOG_FILE"; then
51+
if brakeman -q -o "$BRAKEMAN_TEXT" --force "$TARGET_PATH" 2>/dev/null; then
5252
echo "[run_brakeman.sh][Brakeman] Text report generation completed." | tee -a "$LOG_FILE"
5353
else
5454
echo "[run_brakeman.sh][Brakeman] Text report generation failed." >> "$LOG_FILE"

scripts/tools/run_burp.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ if [ -f "/opt/burp/burp-suite.jar" ]; then
2929
# Note: Burp Suite Community Edition has limited CLI capabilities
3030
# For now, we'll run basic scan and generate reports
3131
# Generate JSON report (if supported)
32-
if java -jar /opt/burp/burp-suite.jar -c "$BURP_CONFIG_PATH" -u "$ZAP_TARGET" -o "$BURP_JSON" 2>>"$LOG_FILE"; then
32+
if java -jar /opt/burp/burp-suite.jar -c "$BURP_CONFIG_PATH" -u "$ZAP_TARGET" -o "$BURP_JSON" 2>/dev/null; then
3333
echo "[run_burp.sh][Burp] JSON report generation completed." | tee -a "$LOG_FILE"
3434
else
3535
echo "[run_burp.sh][Burp] JSON report generation failed." >> "$LOG_FILE"
3636
fi
3737

3838
# Generate text report (fallback)
39-
if java -jar /opt/burp/burp-suite.jar -c "$BURP_CONFIG_PATH" -u "$ZAP_TARGET" -o "$BURP_TEXT" 2>>"$LOG_FILE"; then
39+
if java -jar /opt/burp/burp-suite.jar -c "$BURP_CONFIG_PATH" -u "$ZAP_TARGET" -o "$BURP_TEXT" 2>/dev/null; then
4040
echo "[run_burp.sh][Burp] Text report generation completed." | tee -a "$LOG_FILE"
4141
else
4242
echo "[run_burp.sh][Burp] Text report generation failed." >> "$LOG_FILE"

scripts/tools/run_checkov.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ if command -v checkov &>/dev/null; then
4343

4444
# Generate JSON report for multiple frameworks
4545
# Note: Not limiting to --framework terraform, using default auto-detection
46-
checkov -d "$TARGET_PATH" --output json --output-file "$CHECKOV_JSON" --quiet 2>>"$LOG_FILE" || {
46+
checkov -d "$TARGET_PATH" --output json --output-file "$CHECKOV_JSON" --quiet 2>/dev/null || {
4747
echo "[run_checkov.sh][Checkov] JSON report generation failed." >> "$LOG_FILE"
4848
# Create minimal JSON if generation fails
4949
echo '{"check_type":"","results":{"passed_checks":[],"failed_checks":[],"skipped_checks":[]},"summary":{"passed":0,"failed":0,"skipped":0}}' > "$CHECKOV_JSON"
5050
}
5151

5252
# Generate text report (output to stdout, redirect to file)
53-
checkov -d "$TARGET_PATH" --output cli --quiet 2>>"$LOG_FILE" > "$CHECKOV_TEXT" || {
53+
checkov -d "$TARGET_PATH" --output cli --quiet 2>/dev/null > "$CHECKOV_TEXT" || {
5454
echo "[run_checkov.sh][Checkov] Text report generation failed." >> "$LOG_FILE"
5555
echo "Checkov scan completed but no results available." > "$CHECKOV_TEXT"
5656
}

scripts/tools/run_clair.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if command -v clair &>/dev/null; then
4040
echo "[run_clair.sh][Clair][WARNING] Please ensure Clair server is running separately." | tee -a "$LOG_FILE"
4141

4242
# Create placeholder output since Clair requires complex setup
43-
echo "{\"vulnerabilities\": [], \"note\": \"Clair requires PostgreSQL database setup. Please use Trivy for container scanning.\"}" > "$CLAIR_JSON" 2>>"$LOG_FILE"
43+
echo "{\"vulnerabilities\": [], \"note\": \"Clair requires PostgreSQL database setup. Please use Trivy for container scanning.\"}" > "$CLAIR_JSON" 2>/dev/null
4444

4545
echo "[run_clair.sh][Clair] Placeholder report generated (Clair requires PostgreSQL setup)" | tee -a "$LOG_FILE"
4646

scripts/tools/run_codeql.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ if command -v codeql &>/dev/null; then
7070
# Disable autobuilder for C++ in Docker to avoid npm install issues with read-only filesystem
7171
if [ "$lang" = "cpp" ]; then
7272
echo "[run_codeql.sh][CodeQL] Creating C++ database without autobuilder (to avoid read-only filesystem issues)..." | tee -a "$LOG_FILE"
73-
codeql database create "$CODEQL_DB_DIR-$lang" --language="$lang" --source-root="$TARGET_PATH" --command="" --threads=4 2>>"$LOG_FILE" || {
73+
codeql database create "$CODEQL_DB_DIR-$lang" --language="$lang" --source-root="$TARGET_PATH" --command="" --threads=4 >/dev/null 2>&1 || {
7474
echo "[run_codeql.sh][CodeQL] Database creation failed for $lang" | tee -a "$LOG_FILE"
7575
continue
7676
}
7777
else
78-
codeql database create "$CODEQL_DB_DIR-$lang" --language="$lang" --source-root="$TARGET_PATH" --threads=4 2>>"$LOG_FILE" || {
78+
codeql database create "$CODEQL_DB_DIR-$lang" --language="$lang" --source-root="$TARGET_PATH" --threads=4 >/dev/null 2>&1 || {
7979
echo "[run_codeql.sh][CodeQL] Database creation failed for $lang" | tee -a "$LOG_FILE"
8080
continue
8181
}
@@ -93,7 +93,7 @@ if command -v codeql &>/dev/null; then
9393
# Convert SARIF to JSON for processing (using SARIF as JSON since they're compatible formats)
9494
if [ -f "$CODEQL_SARIF-$lang" ]; then
9595
echo "[run_codeql.sh][CodeQL] Copying SARIF as JSON for $lang..." | tee -a "$LOG_FILE"
96-
cp "$CODEQL_SARIF-$lang" "$CODEQL_JSON-$lang" 2>>"$LOG_FILE" || {
96+
cp "$CODEQL_SARIF-$lang" "$CODEQL_JSON-$lang" 2>/dev/null || {
9797
echo "[run_codeql.sh][CodeQL] Copy failed for $lang" | tee -a "$LOG_FILE"
9898
}
9999
fi
@@ -104,7 +104,7 @@ if command -v codeql &>/dev/null; then
104104
codeql database interpret-results "$CODEQL_DB_DIR-$lang" \
105105
--format=sarif-latest \
106106
"$CODEQL_SARIF-$lang" \
107-
--output="$CODEQL_TEXT-$lang" 2>>"$LOG_FILE" || {
107+
--output="$CODEQL_TEXT-$lang" >/dev/null 2>&1 || {
108108
echo "[run_codeql.sh][CodeQL] Text report generation failed for $lang" | tee -a "$LOG_FILE"
109109
# Create empty text file if interpretation fails
110110
echo "CodeQL analysis completed but report interpretation failed." > "$CODEQL_TEXT-$lang"

scripts/tools/run_detect_secrets.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ if command -v detect-secrets &>/dev/null; then
2525

2626
# Run secret detection scan with JSON output
2727
echo "[run_detect_secrets.sh][Detect-secrets] Running secret detection scan..." | tee -a "$LOG_FILE"
28-
detect-secrets scan --all-files "$TARGET_PATH" > "$DETECT_SECRETS_JSON" 2>>"$LOG_FILE" || {
28+
detect-secrets scan --all-files "$TARGET_PATH" > "$DETECT_SECRETS_JSON" 2>/dev/null || {
2929
echo "[run_detect_secrets.sh][Detect-secrets] JSON report generation failed." >> "$LOG_FILE"
3030
}
3131

3232
# Generate text report
3333
echo "[run_detect_secrets.sh][Detect-secrets] Running text report generation..." | tee -a "$LOG_FILE"
34-
detect-secrets scan --all-files "$TARGET_PATH" > "$DETECT_SECRETS_TEXT" 2>>"$LOG_FILE" || {
34+
detect-secrets scan --all-files "$TARGET_PATH" > "$DETECT_SECRETS_TEXT" 2>/dev/null || {
3535
echo "[run_detect_secrets.sh][Detect-secrets] Text report generation failed." >> "$LOG_FILE"
3636
}
3737

scripts/tools/run_docker_bench.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ if command -v docker-bench-security &>/dev/null; then
3434

3535
# Run docker-bench-security from its directory with JSON and text outputs
3636
cd /opt/docker-bench-security
37-
./docker-bench-security.sh > "$DOCKER_BENCH_TEXT" 2>>"$LOG_FILE" || {
37+
./docker-bench-security.sh > "$DOCKER_BENCH_TEXT" 2>/dev/null || {
3838
echo "[run_docker_bench.sh][Docker Bench] Text report generation failed." >> "$LOG_FILE"
3939
}
4040
cd "$(dirname "$0")/../.."
4141

4242
# Convert text output to JSON format (basic conversion)
4343
if [ -f "$DOCKER_BENCH_TEXT" ]; then
4444
# Parse text output and convert to JSON
45-
python3 - "$DOCKER_BENCH_TEXT" > "$DOCKER_BENCH_JSON" 2>>"$LOG_FILE" << 'PYEOF'
45+
python3 - "$DOCKER_BENCH_TEXT" > "$DOCKER_BENCH_JSON" 2>/dev/null << 'PYEOF'
4646
import json
4747
import re
4848
import sys

scripts/tools/run_gitleaks.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ if command -v gitleaks &>/dev/null; then
2525

2626
# Run secret detection scan with JSON output
2727
echo "[run_gitleaks.sh][GitLeaks] Running secret detection scan..." | tee -a "$LOG_FILE"
28-
gitleaks detect --source "$TARGET_PATH" --report-path "$GITLEAKS_JSON" --no-git 2>>"$LOG_FILE" || {
28+
gitleaks detect --source "$TARGET_PATH" --report-path "$GITLEAKS_JSON" --no-git 2>/dev/null || {
2929
echo "[run_gitleaks.sh][GitLeaks] JSON report generation failed." >> "$LOG_FILE"
3030
}
3131

3232
# Generate text report (redirect stdout to file, since gitleaks text output goes to stdout)
3333
echo "[run_gitleaks.sh][GitLeaks] Running text report generation..." | tee -a "$LOG_FILE"
34-
gitleaks detect --source "$TARGET_PATH" --no-git --verbose > "$GITLEAKS_TEXT" 2>>"$LOG_FILE" || {
34+
gitleaks detect --source "$TARGET_PATH" --no-git --verbose > "$GITLEAKS_TEXT" 2>/dev/null || {
3535
echo "[run_gitleaks.sh][GitLeaks] Text report generation failed." >> "$LOG_FILE"
3636
# Even if the command fails with exit code 1 (secrets found), we still get output
3737
if [ ! -s "$GITLEAKS_TEXT" ]; then

0 commit comments

Comments
 (0)