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
2.8 KiB
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
-
Added logging imports:
use tracing::{debug, info}; -
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)")
-
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)
-
Fixed loop iteration: Changed
for page in pagestofor (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- OKtest_detect_javascript_no_javascript- OKtest_detect_javascript_with_acroform_field_js- OKtest_detect_javascript_with_annotation_js- OKtest_detect_javascript_with_catalog_aa_js- OKtest_detect_javascript_with_catalog_openaction_js- OKtest_detect_javascript_with_page_aa_js- OK- Plus 21 other detection tests - OK
Acceptance Criteria
- ✅ PASS:
log::debug!orlog::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