pdftract/notes/bf-2pyg1.md
jedarden 440e8fd075 feat(bf-2pxsu): add logging for JavaScript execution attempts
Add warning-level logging at all JavaScript detection points in pdftract-core:

- Add warn import to tracing macros in detection.rs
- Add 'JavaScript execution attempted but not supported' warning at 6 detection points:
  - Catalog /OpenAction detection
  - Catalog /AA (Additional Actions) detection
  - Page-level /AA detection
  - Page annotation /A (primary action) detection
  - Page annotation /AA (additional actions) detection
  - AcroForm fields /AA detection
- Each warning references TH-04 threat model and states detection-only posture

Verification: notes/bf-2pxsu.md
Tests: All 46 detection tests pass
Acceptance criteria: PASS (compilation, logging, context, warnings)

Closes bf-2pxsu
2026-07-05 16:33:48 -04:00

2.8 KiB

Verification Note: bf-2pyg1 - Debug logging for JavaScript detection

Summary

Successfully added debug logging for JavaScript detection in the pdftract-core crate.

Changes Made

File: crates/pdftract-core/src/detection.rs

  1. Added logging imports: use tracing::{debug, info};

  2. Added info-level logs at JavaScript detection points in detect_javascript():

    • info!("JavaScript actions detected: catalog /OpenAction")
    • info!("JavaScript actions detected: catalog /AA (Additional Actions)")
    • info!("JavaScript actions detected: page {} /AA (Additional Actions)", page_idx)
    • info!("JavaScript actions detected: page {} annotation /A (primary action)", page_idx)
    • info!("JavaScript actions detected: page {} annotation /AA (additional actions)", page_idx)
    • info!("JavaScript actions detected: AcroForm fields /AA (Additional Actions)")
  3. Added debug-level logs in helper functions:

    • debug!("JavaScript action detected with /S == {}", s_name)
    • debug!("JavaScript action detected with /JS entry")
    • debug!("JavaScript detected in /AA dictionary with action key: /{}", key)
  4. Fixed loop iteration: Changed for page in pages to for (page_idx, page) in pages.iter().enumerate() to provide page index context in logs

Verification Results

Compilation

PASS: Code compiles successfully with cargo check --package pdftract-core

Tests

PASS: All 28 detection tests pass:

  • test_detect_javascript_empty - OK
  • test_detect_javascript_no_javascript - OK
  • test_detect_javascript_with_acroform_field_js - OK
  • test_detect_javascript_with_annotation_js - OK
  • test_detect_javascript_with_catalog_aa_js - OK
  • test_detect_javascript_with_catalog_openaction_js - OK
  • test_detect_javascript_with_page_aa_js - OK
  • Plus 21 other detection tests - OK

Acceptance Criteria

  • PASS: log::debug! or log::info! macro added at JavaScript detection point
  • PASS: Log message clearly states 'JavaScript actions detected' or similar
  • PASS: Log includes relevant context (page indices, action types, locations)
  • PASS: Code compiles successfully

Technical Details

The implementation uses the tracing crate (already used in the codebase) with both info! and debug! macros:

  • info! for high-level detection events (what was found and where)
  • debug! for detailed detection internals (specific keys and subtypes)

All log messages provide clear context about:

  • Location: catalog level, page level, annotation level, or AcroForm fields
  • Type: /OpenAction, /AA (Additional Actions), /A (primary action)
  • Context: Page indices for page-level detections

Commit Information

  • Commit: (to be created with git commit)
  • Files modified: crates/pdftract-core/src/detection.rs