Skip to content

Fix path traversal and hardcoded secrets in web server; modernize local scripts#155

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-full-on-review-issue
Draft

Fix path traversal and hardcoded secrets in web server; modernize local scripts#155
Copilot wants to merge 4 commits intomainfrom
copilot/fix-full-on-review-issue

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Description

Comprehensive code review identified 2 network-exposed vulnerabilities in hardware_database_server.py (binds to 0.0.0.0:5000) and opportunities to modernize local script patterns.

Security Fixes (Network-Exposed)

Path Traversal (Critical)

@app.route('/api/download/<hardware_id>')
def download_config(hardware_id):
    # Before: No validation, direct path construction
    profile_file = UPLOADS_PATH / f"{hardware_id}.json"
    
    # After: Validation + TOCTOU-resistant resolution
    if not re.match(r'^[a-zA-Z0-9_-]+$', hardware_id):
        return "Invalid hardware ID format", 400
    
    profile_file = profile_file.resolve()
    if not str(profile_file).startswith(str(UPLOADS_PATH.resolve())):
        return "Invalid file path", 400

Hardcoded SECRET_KEY

# Before: Hardcoded secret visible in repo
app.config['SECRET_KEY'] = 'phoenix_guard_hardware_db'

# After: Environment variable or secure random generation
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', secrets.token_hex(32))

Code Modernization (Local Scripts)

Not exploitable (user already has shell access), but improves maintainability:

  • scripts/uefi-tools/uuefi-apply.sh: eval "$*""$@" (predictable quoting)

  • scripts/secure-boot/keys-centralize.sh: eval "$*""$@" (predictable quoting)

  • scripts/validation/detect_bootkit.py: os.system()subprocess.run() (modern API)

  • scripts/recovery/autonuke.py: Added shlex.split(), default shell=False

  • scripts/recovery/nuclear-wipe.sh: Extracted device validation to function (DRY)

  • scripts/secure-boot/enable-secureboot-kexec.sh: Predictable path → mktemp

  • scripts/secure-boot/enable-secureboot-kexec.sh: Fixed glob pattern in conditional

  • Breaking change?

  • Impacts security?

  • Includes tests?

How This Was Tested

  • CodeQL: 0 alerts
  • Shellcheck: No critical errors
  • Python syntax validation

Integration Instructions

Production deployments should set SECRET_KEY environment variable for web/hardware_database_server.py. Random key generated if unset (invalidates sessions on restart).

Original prompt

This section details on the original issue you should resolve

<issue_title>Full on review</issue_title>
<issue_description>For correctnes and posterity.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 30, 2026 03:35
…ath traversal, insecure temp files

Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
… and ARGS word splitting

Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with full review correctness Security: Fix command injection, path traversal, and hardcoded secrets Jan 30, 2026
Copilot AI requested a review from P4X-ng January 30, 2026 03:45
Copilot AI changed the title Security: Fix command injection, path traversal, and hardcoded secrets Fix path traversal and hardcoded secrets in web server; modernize local scripts Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full on review

2 participants