Skip to content

Validate slide PDF downloads before writing - #51142

Merged
pelikhan merged 4 commits into
mainfrom
copilot/uk-ai-resilience-gov-scan-ensure-docs-pdf
Aug 7, 2026
Merged

Validate slide PDF downloads before writing#51142
pelikhan merged 4 commits into
mainfrom
copilot/uk-ai-resilience-gov-scan-ensure-docs-pdf

Conversation

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code scanning flagged scripts/ensure-docs-slide-pdf.js for writing network-derived data to disk without sufficient validation. The script now constrains the download source and validates response metadata and PDF bytes before writing.

  • Download source hardening

    • Builds the slide deck URL from validated owner/repo and commit SHA components.
    • Restricts downloads to https://media.githubusercontent.com.
    • Rejects dot-only repository path segments.
  • Response and content validation

    • Accepts only PDF-compatible content types.
    • Rejects malformed or oversized content-length values.
    • Enforces a maximum downloaded size.
    • Verifies the %PDF- signature before returning bytes for file write.
  • Focused coverage

    • Adds script-level tests for unsafe URL components, invalid content types, malformed sizes, oversized downloads, and non-PDF bytes.
validateSlideDeckResponse(response);

const downloadedBytes = Buffer.from(await response.arrayBuffer());
return validatePdfBytes(downloadedBytes, `Downloaded slide deck from ${url}`);

Copilot AI and others added 3 commits August 7, 2026 17:06
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix untrusted data file write in ensure-docs-slide-pdf.js Validate slide PDF downloads before writing Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Excellent work on addressing the security vulnerability! This PR hardens PDF download handling in scripts/ensure-docs-slide-pdf.js by adding comprehensive validation for network-derived files before writing to disk.

What's Aligned

Focused scope — The PR isolates a single security concern: validating slide PDF downloads
Complete test coverage — New test file covers unsafe URLs, invalid content types, malformed sizes, oversized downloads, and non-PDF bytes
Clear implementation — URL component validation (SHA, repo path), content-type guards, size limits, and PDF signature verification
Security-first — Follows defense-in-depth with multiple validation layers
Detailed description — Clearly explains the problem, solution approach, and specific changes
Proper issue linkage — References #51127
Core team workflow — Authored by copilot-swe-agent, aligned with the project's agentic development model

Ready for Review

This PR is in draft and appears ready for transition to ready-for-review when the author determines implementation is complete. The code follows the project's patterns, includes defensive documentation (LGTM comment), and integrates well with existing PDF handling logic.

Generated by ✅ Contribution Check · auto · 84.8 AIC · ⊞ 8.7K ·

Copilot AI requested a review from pelikhan August 7, 2026 17:26
@pelikhan
pelikhan marked this pull request as ready for review August 7, 2026 17:29
Copilot AI balanced review requested due to automatic review settings August 7, 2026 17:29
@pelikhan
pelikhan merged commit 506e019 into main Aug 7, 2026
@pelikhan
pelikhan deleted the copilot/uk-ai-resilience-gov-scan-ensure-docs-pdf branch August 7, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens slide PDF downloads before writing them to disk.

Changes:

  • Validates trusted URL components, response metadata, size, and PDF signatures.
  • Adds focused validation tests.
Show a summary per file
File Description
scripts/ensure-docs-slide-pdf.js Adds download and PDF validation.
scripts/ensure-docs-slide-pdf.test.js Tests validation and URL hardening.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

}
validateSlideDeckResponse(response);

const downloadedBytes = Buffer.from(await response.arrayBuffer());

assertThrowsMatching(() => buildSlideDeckUrl("github/gh-aw", "main"), /Unsafe git ref/, "rejects non-SHA git ref");

console.log("All ensure-docs-slide-pdf tests passed.");
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.1

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.

[uk-ai-resilience] [gov-scan] Untrusted-data file write in scripts/ensure-docs-slide-pdf.js (alert #654)

3 participants