Skip to content

Commit 430675d

Browse files
[Metro][Traffic Agent] Fix security vulnerabilities (#1945)
1 parent 219dffa commit 430675d

File tree

9 files changed

+524
-453
lines changed

9 files changed

+524
-453
lines changed

metro-ai-suite/smart-traffic-intersection-agent/Makefile

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ TEST_TARGETS := $(addprefix test-,$(TEST_COMPONENTS))
9999
clean-all clean-all-keep-models \
100100
shellcheck pylint ruff \
101101
trivy-scan trivy-scan-fs trivy-scan-image trivy-scan-config \
102-
clamav-scan bandit-scan gitleaks-scan codeql-scan \
102+
clamav-scan bandit-scan-new bandit-scan gitleaks-scan codeql-scan codeql-scan-new \
103103
$(TEST_TARGETS) \
104104
get-service-name get-component-names get-image-tags get-context-dirs \
105105
get-python-version get-scan-matrix-json
@@ -403,6 +403,28 @@ clamav-scan:
403403
> security-results/clamav-$(SERVICE_NAME)-$$(date +%Y%m%d-%H%M%S).txt 2>&1 || true
404404
@echo "✅ ClamAV scan complete: security-results/clamav-*"
405405

406+
bandit-scan-new:
407+
@echo "🔐 Running Bandit Security Scan..."
408+
@mkdir -p security-results
409+
@python3 -m venv bandit-venv && \
410+
source bandit-venv/bin/activate && \
411+
pip install --upgrade pip && \
412+
pip install bandit[toml] && \
413+
CONFIG_OPT=""; \
414+
if [ -f "pyproject.toml" ]; then CONFIG_OPT="-c pyproject.toml"; fi; \
415+
echo "📝 Generating TXT Report (matches CI)..." && \
416+
bandit $$CONFIG_OPT --severity-level low --confidence-level low -r src/ tests/ \
417+
-f txt -o security-results/bandit-report-$(SERVICE_NAME).txt || true && \
418+
echo "📊 Generating JSON Report..." && \
419+
bandit $$CONFIG_OPT --severity-level low --confidence-level low -r src/ tests/ \
420+
-f json -o security-results/bandit-report-$(SERVICE_NAME).json || true && \
421+
echo "🌐 Generating HTML Report..." && \
422+
bandit $$CONFIG_OPT --severity-level low --confidence-level low -r src/ tests/ \
423+
-f html -o security-results/bandit-report-$(SERVICE_NAME).html || true && \
424+
deactivate && \
425+
rm -rf bandit-venv
426+
@echo "✅ Bandit scan complete. Check security-results/ for txt, json, and html reports."
427+
406428
bandit-scan:
407429
@echo "🔐 Running Bandit Security Scan..."
408430
@mkdir -p security-results
@@ -428,6 +450,54 @@ gitleaks-scan:
428450
-r security-results/gitleaks-$(SERVICE_NAME)-$$(date +%Y%m%d-%H%M%S).json || true
429451
@echo "✅ Gitleaks scan complete: security-results/gitleaks-*"
430452

453+
codeql-scan-new:
454+
@echo "🛡️ Running CodeQL Security Analysis..."
455+
@if ! command -v codeql >/dev/null 2>&1; then \
456+
echo "❌ CodeQL CLI is not installed. Install: https://github.com/github/codeql-cli-binaries/releases"; \
457+
exit 1; \
458+
fi
459+
460+
@mkdir -p security-results
461+
462+
@echo "→ Creating CodeQL database for Python..."
463+
@codeql database create security-results/codeql-db-python-$(SERVICE_NAME) \
464+
--language=python \
465+
--source-root=. \
466+
--build-mode=none \
467+
--overwrite 2>&1 | tail -5
468+
469+
@echo "→ Updating CodeQL Python Query Packs..."
470+
@codeql pack download codeql/python-queries
471+
472+
@echo "→ Running CodeQL analysis (SARIF)..."
473+
@codeql database analyze security-results/codeql-db-python-$(SERVICE_NAME) \
474+
codeql/python-queries \
475+
--format=sarif-latest \
476+
--output=security-results/codeql-python-$(SERVICE_NAME).sarif || true
477+
478+
@echo "→ Running CodeQL analysis (CSV)..."
479+
@codeql database analyze security-results/codeql-db-python-$(SERVICE_NAME) \
480+
codeql/python-queries \
481+
--format=csv \
482+
--output=security-results/codeql-python-$(SERVICE_NAME).csv || true
483+
484+
@echo "→ Converting CSV to JSON..."
485+
@if [ -f security-results/codeql-python-$(SERVICE_NAME).csv ]; then \
486+
python3 -c "import csv,json; h=['name','description','severity','message','path','start_line','start_col','end_line','end_col']; rows=[dict(zip(h,r)) for r in csv.reader(open('security-results/codeql-python-$(SERVICE_NAME).csv')) if r]; json.dump(rows,open('security-results/codeql-python-$(SERVICE_NAME).json','w'),indent=2); print(' Converted '+str(len(rows))+' finding(s) to JSON')"; \
487+
else \
488+
echo " ⚠️ No CSV findings to convert."; \
489+
fi
490+
491+
@echo "→ Converting SARIF to HTML..."
492+
@if [ -f security-results/codeql-python-$(SERVICE_NAME).sarif ]; then \
493+
python3 -c "import json,html; s=json.load(open('security-results/codeql-python-$(SERVICE_NAME).sarif')); fs=[{'id':r.get('ruleId',''),'sev':r.get('level','warning'),'msg':r.get('message',{}).get('text',''),'path':r.get('locations',[{}])[0].get('physicalLocation',{}).get('artifactLocation',{}).get('uri',''),'line':r.get('locations',[{}])[0].get('physicalLocation',{}).get('region',{}).get('startLine',0)} for run in s.get('runs',[]) for r in run.get('results',[])]; rows=''.join(['<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%s:%s</td></tr>'%(i+1,html.escape(f['sev']),html.escape(f['id']),html.escape(f['msg'][:200]),html.escape(f['path']),f['line']) for i,f in enumerate(fs)]); open('security-results/codeql-python-$(SERVICE_NAME).html','w').write('<!DOCTYPE html><html><head><meta charset=utf-8><title>CodeQL Report - $(SERVICE_NAME)</title><style>body{font-family:Arial,sans-serif;margin:20px}table{border-collapse:collapse;width:100%%}th,td{border:1px solid #ddd;padding:8px;text-align:left}th{background:#4472C4;color:white}tr:nth-child(even){background:#f2f2f2}</style></head><body><h1>CodeQL Security Report: $(SERVICE_NAME)</h1><p><strong>Total findings:</strong> %d</p><table><tr><th>#</th><th>Severity</th><th>Rule</th><th>Message</th><th>Location</th></tr>%s</table></body></html>'%(len(fs),rows)); print(' Generated HTML report with %d finding(s)'%len(fs))"; \
494+
else \
495+
echo " ⚠️ No SARIF file to convert."; \
496+
fi
497+
498+
@echo "✅ Python analysis complete."
499+
@echo "✅ CodeQL scan complete: security-results/codeql-*"
500+
431501
codeql-scan:
432502
@echo "🛡️ Running CodeQL Security Analysis..."
433503
@if ! command -v codeql >/dev/null 2>&1; then \

metro-ai-suite/smart-traffic-intersection-agent/docker/agent-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ services:
5252
build:
5353
context: ${APP_DIR:-..}/src
5454
dockerfile: Dockerfile
55-
image: ${REGISTRY:-}smart-traffic-intersection-agent:${TAG:-1.0.0-rc1}
55+
image: ${REGISTRY:-}smart-traffic-intersection-agent:${TAG:-1.0.0-rc2}
5656
ports:
5757
- "${AGENT_BACKEND_PORT:-}:8081"
5858
- "${AGENT_UI_PORT:-}:7860"

metro-ai-suite/smart-traffic-intersection-agent/docs/user-guide/get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ an introduction.
2323
- **Registry configuration**: To pull pre-built images from a specific registry, set the `REGISTRY` and `TAG` parameters. Following is the recommended default setting.
2424
```bash
2525
export REGISTRY="intel"
26-
export TAG="1.0.0-rc1"
26+
export TAG="1.0.0-rc2"
2727
```
2828

2929

metro-ai-suite/smart-traffic-intersection-agent/docs/user-guide/release-notes.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Release Notes
22

3-
## Current Release: 1.0.0-rc1
3+
## Current Release: 1.0.0-rc2
4+
5+
**Release Date**: 27 Feb 2026
6+
7+
### Features
8+
9+
- Fixed security vulnerabities in code
10+
- Update base image to python:3.13-slim
11+
12+
## Previous Releases: 1.0.0-rc1
413

514
**Release Date**: 17 Feb 2026
615

metro-ai-suite/smart-traffic-intersection-agent/src/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
FROM python:3.11-slim
4+
FROM python:3.13-slim
55

66
# Set working directory
77
WORKDIR /app
@@ -21,6 +21,9 @@ COPY . .
2121
# Create virtual environment and install dependencies using uv
2222
RUN uv sync && uv pip install -r ui/requirements.txt
2323

24+
# Copy license file
25+
COPY third_party_programs.txt /licenses/third_party_programs.txt
26+
2427
# Create non-root user and adjust permissions
2528
RUN useradd -m -u 1000 traffic && \
2629
chmod +x docker-entrypoint.sh && \

metro-ai-suite/smart-traffic-intersection-agent/src/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ dependencies = [
1212
"paho-mqtt==2.1.0",
1313
"aiohttp==3.13.3",
1414
"structlog==23.2.0",
15-
"pydantic==2.7.0",
15+
"pydantic==2.9.2",
1616
"python-dateutil==2.8.2",
1717
"python-dotenv==1.0.0",
18-
"gradio==5.49.1",
19-
"pillow>=9.0.0",
18+
"gradio==6.2.0",
19+
"pillow>=12.1.1,<13.0",
2020
"markdown>=3.4.0",
2121
"requests==2.32.5",
2222
"huggingface_hub==0.36.0",

metro-ai-suite/smart-traffic-intersection-agent/third_party_programs.txt renamed to metro-ai-suite/smart-traffic-intersection-agent/src/third_party_programs.txt

File renamed without changes.

metro-ai-suite/smart-traffic-intersection-agent/src/ui/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ def main():
278278
server_port=Config.get_app_port(),
279279
share=False,
280280
show_error=True,
281-
show_api=False,
282281
quiet=False
283282
)
284283

0 commit comments

Comments
 (0)