Skip to content

Harden workflows and Flask routes for CodeQL findings (permissions, path handling, error leakage) - #96

Draft
ariedotcodotnz with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts
Draft

ariedotcodotnz with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts

Conversation

Copilot AI commented Sep 20, 2026 •

Copy link
Copy Markdown

This PR addresses the targeted code-scanning findings by applying least-privilege workflow permissions and tightening Flask-side security checks. It updates the flagged areas across GitHub Actions and web routes with minimal, localized changes.

  • Workflow security: explicit token permissions

    • Added permissions blocks to workflow/job definitions that were relying on default broad GITHUB_TOKEN scopes.
    • Set read-only contents where sufficient, and retained required write scope only for SARIF upload (security-events: write).
  • Path-injection hardening in admin log endpoints

    • Replaced prefix-based path checks with canonical containment checks using os.path.realpath + os.path.commonpath.
    • Switched file read/download/truncate operations to resolved canonical paths after validation.
  • Stack-trace / exception detail exposure reduction

    • Removed raw exception text from user-facing API and validation responses in generation/SVG/health/override flows.
    • Kept detailed diagnostics in server logs (logger.exception) while returning stable generic messages to clients.
  • Alert triage outcome

    • Marked one style-route alert as a false positive (style_id is typed as int, filename is deterministic, and serving is constrained to a fixed directory via send_from_directory).
def _is_safe_path(base_dir, candidate_path):
    real_base_dir = os.path.realpath(base_dir)
    real_candidate_path = os.path.realpath(candidate_path)
    return os.path.commonpath([real_base_dir, real_candidate_path]) == real_base_dir

Co-authored-by: ariedotcodotnz <78839335+ariedotcodotnz@users.noreply.github.com>
return redirect(url_for('admin.error_logs'))

if os.path.exists(filepath):
if os.path.exists(real_filepath):
if os.path.exists(real_filepath):
try:
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
with open(real_filepath, 'r', encoding='utf-8', errors='replace') as f:
return redirect(url_for('admin.error_logs'))

if not os.path.exists(filepath):
if not os.path.exists(real_filepath):
log_activity('admin_action', f'Downloaded log file: {filename}')

return send_file(filepath, as_attachment=True, download_name=filename)
return send_file(real_filepath, as_attachment=True, download_name=filename)
return redirect(url_for('admin.error_logs'))

if not os.path.exists(filepath):
if not os.path.exists(real_filepath):
try:
# Truncate the file
with open(filepath, 'w') as f:
with open(real_filepath, 'w', encoding='utf-8') as f:
Copilot AI changed the title [WIP] Fix code scanning alerts flagged in repository Harden workflows and Flask routes for CodeQL findings (permissions, path handling, error leakage) Sep 20, 2026

This branch has not been deployed

No deployments
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.

3 participants