npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pdf-xss-checker

v1.0.1

Published

A Node.js package to verify if PDFs contain XSS vulnerabilities

Readme

PDF XSS Checker

npm version

A Node.js package to verify if PDFs contain XSS (Cross-Site Scripting) vulnerabilities.

Installation

npm install pdf-xss-checker

Features

  • PDF Content Extraction: Extracts and analyzes text content from PDF files
  • XSS Detection: Identifies potential XSS vulnerabilities using pattern matching
  • JavaScript Injection Detection: Detects JavaScript code that could lead to security issues
  • Form Injection Detection: Identifies form-based attack vectors
  • Simple API: Easy-to-use API for both file and buffer inputs
  • Detailed Reporting: Comprehensive vulnerability reports with location information
  • Command-line Interface: Scan PDFs directly from the terminal
  • Configurable Security Rules: Adjust detection thresholds based on your security needs

Usage

API Usage

const pdfXssChecker = require('pdf-xss-checker');

// Scan a PDF file
async function checkPdf() {
  try {
    const results = await pdfXssChecker.scanPdf('./document.pdf');
    
    if (results.success) {
      console.log(`Safe to use: ${results.safeToUse ? 'Yes' : 'No'}`);
      console.log(`Found ${results.vulnerabilities.length} potential vulnerabilities`);
      
      // Print vulnerabilities
      results.vulnerabilities.forEach(vuln => {
        console.log(`- ${vuln.name}: ${vuln.description} (${vuln.severity})`);
      });
    } else {
      console.error(`Error: ${results.error}`);
    }
  } catch (error) {
    console.error('Error scanning PDF:', error);
  }
}

// Scan a PDF buffer
async function checkBuffer(buffer) {
  try {
    const results = await pdfXssChecker.scanBuffer(buffer);
    console.log(`PDF is safe to use: ${results.safeToUse}`);
    return results;
  } catch (error) {
    console.error('Error scanning buffer:', error);
  }
}

Advanced Options

const options = {
  threshold: 'medium', // Severity threshold: 'low', 'medium', 'high', 'critical'
  detectors: ['xss', 'js', 'form'], // Which detectors to use
  includeRawContent: false, // Include raw PDF content in results
  maxContentLength: 10000000 // Maximum content length to analyze (10MB)
};

const results = await pdfXssChecker.scanPdf('./document.pdf', options);

Command-line Usage

# Basic usage
npx pdf-xss-check document.pdf

# With options
npx pdf-xss-check document.pdf --threshold low --verbose --output results.json

# Help
npx pdf-xss-check --help

CLI Options

Usage: pdf-xss-check [options] <file>

Check PDF files for XSS vulnerabilities

Arguments:
  file                     PDF file to scan

Options:
  -V, --version            output the version number
  -t, --threshold <level>  Detection threshold (low, medium, high, critical) (default: "medium")
  -v, --verbose           Show detailed output (default: false)
  -j, --json              Output results as JSON (default: false)
  -o, --output <file>     Write results to file
  --include-content       Include raw content in the report (may be large) (default: false)
  --include-grouped       Include grouped vulnerabilities in the report (default: false)
  -h, --help             display help for command

Detection Patterns

The package checks for various XSS and injection patterns, including:

  • Script tags (<script>)
  • JavaScript protocol usage (javascript:)
  • Event handlers (onclick, etc.)
  • iFrame elements
  • Document manipulation functions
  • JavaScript execution functions (eval, etc.)
  • Form injection vectors
  • PDF-specific JavaScript API calls

Results Format

The scan results include:

{
  success: true,
  summary: {
    fileName: 'document.pdf',
    timestamp: '2025-01-01T12:00:00.000Z',
    pageCount: 5,
    vulnerabilityCount: 3,
    riskLevel: 'medium',
    safeToUse: false,
    severityCounts: { medium: 2, high: 1 },
    typeCounts: { xss: 2, 'js-injection': 1 }
  },
  metadata: {
    info: { /* PDF metadata */ },
    pageCount: 5,
    contentLength: 12345
  },
  vulnerabilities: [
    {
      type: 'xss',
      name: 'Script Tag',
      description: 'Found <script> tags that may execute JavaScript',
      severity: 'high',
      matchedText: '<script>alert("XSS")</script>',
      location: {
        startIndex: 1234,
        endIndex: 1260,
        line: 42,
        column: 10
      },
      context: '...text before <script>alert("XSS")</script> text after...'
    },
    // More vulnerabilities...
  ]
}

License

MIT