Skip to content

Add some fixes for security vulnerabilities #40

Merged
superm1 merged 4 commits into
masterfrom
superm1/security
May 27, 2026
Merged

Add some fixes for security vulnerabilities #40
superm1 merged 4 commits into
masterfrom
superm1/security

Conversation

@superm1
Copy link
Copy Markdown
Owner

@superm1 superm1 commented May 27, 2026

No description provided.

superm1 and others added 4 commits May 27, 2026 19:53
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Escape database-sourced content before rendering in HTML reports to
prevent XSS attacks. Database content from ACPI tables, BIOS strings,
kernel logs, and power rail labels is now properly escaped using
html.escape() before being incorporated into HTML output.

Changes:
- Add HTML escaping to get_cycle_data() for cycle data and debug messages
- Add HTML escaping to get_prereq_data() for prerequisite debug messages
- Add HTML escaping to power rail summary data
- Use markupsafe.Markup to mark pre-escaped HTML as safe

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Enable autoescape=True when creating the Jinja2 Environment to
automatically escape all template variables by default. This provides
defense-in-depth protection against XSS attacks from database-sourced
content rendered in HTML reports.

Variables that contain pre-escaped HTML (constructed with html.escape()
and wrapped in Markup()) are correctly preserved and not double-escaped.

This complements the manual escaping added in the previous commit by
ensuring that any template variables not explicitly handled are still
safely escaped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevent symlink attacks when creating log directories and files as root
via sudo. An attacker could create a symlink at ~/.local/share/amd-debug-tools
or set XDG_DATA_HOME to point to a symlink, causing root to chown
arbitrary files when the tool is run with sudo.

Changes:
- Check if log directory path is a symlink before and after creation
- Use os.lchown() instead of os.chown() to avoid following symlinks
- Use os.open() with O_NOFOLLOW when creating log files
- Fall back to /dev/null if a safe log directory cannot be created
- Verify existing log files are not symlinks before using them

This prevents local privilege escalation where an attacker could:
1. Create symlink at ~/.local/share/amd-debug-tools -> /etc
2. Run the tool with sudo
3. Have root chown /etc to the attacker's UID

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 10.93750% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.19%. Comparing base (58809ad) to head (a990096).
⚠️ Report is 4 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/amd_debug/sleep_report.py 14.28% 30 Missing ⚠️
src/amd_debug/common.py 6.89% 27 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
- Coverage   85.60%   85.19%   -0.42%     
==========================================
  Files          36       36              
  Lines        8073     8119      +46     
  Branches      759      766       +7     
==========================================
+ Hits         6911     6917       +6     
- Misses        940      980      +40     
  Partials      222      222              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@superm1 superm1 merged commit 437ebac into master May 27, 2026
8 of 10 checks passed
@superm1 superm1 deleted the superm1/security branch May 27, 2026 19:07
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.

1 participant