Skip to content

Add Pdf.ContainsJavaScript for detecting embedded JavaScript in PDFs#23

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/detect-javascript-in-pdf
Draft

Add Pdf.ContainsJavaScript for detecting embedded JavaScript in PDFs#23
Copilot wants to merge 2 commits intomainfrom
copilot/detect-javascript-in-pdf

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 4, 2026

No .NET API existed to detect embedded JavaScript in PDF files — a common security requirement for file upload validation. The CLI equivalent is qpdf --json file.pdf | grep -i javascript.

Changes

  • QPdfNet/Info/Pdf.cs — Adds ContainsJavaScript(string fileName) static method: runs qpdf's JSON output pipeline and performs a case-insensitive search for "javascript" in the result, mirroring the CLI grep approach
  • QpdfNetTest/TestFiles/withjavascript.pdf — Minimal valid PDF containing a /S /JavaScript action object, used as test fixture
  • QpdfNetTest/QpdfTests.cs — Adds TestContainsJavaScript and TestContainsNoJavaScript test cases

Usage

if (Pdf.ContainsJavaScript(uploadedFilePath))
{
    // reject or quarantine the file
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Detect JavaScript in a PDF</issue_title>
<issue_description>Hi,

I want to implement security in our application for upload files. My requirement is to detect if there're any javascripts in pdf file. I was wondering if QPdfNet has any function for this.

With command line tool we can use

qpdf –json yourfile.pdf | grep -i javascript</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Sicos1977 <6692947+Sicos1977@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality to detect JavaScript in PDF files Add Pdf.ContainsJavaScript for detecting embedded JavaScript in PDFs Mar 4, 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.

Detect JavaScript in a PDF

2 participants