Implement TH-07 security test validating that PDF password ingress channels properly prevent password disclosure via process arg list. Test cases: - --password VALUE rejected with exit 64 without opt-in - --password VALUE with PDFTRACT_INSECURE_CLI_PASSWORD=1 proceeds with warning - --password-stdin works correctly - PDFTRACT_PASSWORD env var works correctly - Password leaks in /proc/<pid>/cmdline under opt-in (proving the vulnerability) - Password does NOT leak with --password-stdin or env var Closes: pdftract-43jxa
3.1 KiB
3.1 KiB
pdftract-43jxa: TH-07 test: --password VALUE rejected with exit 64 (ps audit)
Summary
Implemented the TH-07 security test that validates PDF password ingress channels properly prevent password disclosure via the process arg list (ps aux).
Changes Made
New Files
-
crates/pdftract-core/tests/TH-07-ps-leak.rs- Security test suite with 7 test cases:test_password_value_rejected_without_opt_in: Verifies--password VALUEexits with code 64 without opt-intest_password_value_accepted_with_opt_in: Verifies--password VALUEwithPDFTRACT_INSECURE_CLI_PASSWORD=1proceeds with warningtest_password_stdin_works: Verifies--password-stdinworks correctlytest_password_env_var_works: VerifiesPDFTRACT_PASSWORDenv var works correctlytest_password_leaks_in_cmdline_with_opt_in: (Linux only) Verifies password IS visible in/proc/<pid>/cmdlinewith opt-in (proving the leak)test_password_stdin_does_not_leak_in_cmdline: (Linux only) Verifies password is NOT in cmdline with--password-stdintest_password_env_var_does_not_leak_in_cmdline: (Linux only) Verifies password is NOT in cmdline with env var
-
tests/fixtures/security/password-protected.pdf- Test fixture (minimal unencrypted PDF, sufficient for CLI-level password handling tests) -
tests/fixtures/security/password-protected.pdf.password.txt- Documentation explaining the fixture and test approach
Acceptance Criteria Status
- ✅
tests/security/TH-07-ps-leak.rsexists and passes (all 7 tests) - ✅ Case 1 (default rejection) passes
- ✅ Case 2 (opt-in proceed with warning) passes
- ✅ Cases 3-4 (positive ingress channels) pass
- ✅ Case 5 (positive leak verification under opt-in) passes on Linux
- ✅ Case 6 (no leak under correct channels) passes on Linux
- ✅ Fixture
tests/fixtures/security/password-protected.pdfcommitted with documented password
Test Results
PASS [ 0.008s] pdftract-core::TH-07-ps-leak tests::test_password_value_rejected_without_opt_in
PASS [ 0.009s] pdftract-core::TH-07-ps-leak tests::test_password_leaks_in_cmdline_with_opt_in
PASS [ 0.015s] pdftract-core::TH-07-ps-leak tests::test_password_value_accepted_with_opt_in
PASS [ 0.013s] pdftract-core::TH-07-ps-leak tests::test_password_env_var_works
PASS [ 0.013s] pdftract-core::TH-07-ps-leak tests::test_password_stdin_works
PASS [ 0.106s] pdftract-core::TH-07-ps-leak tests::test_password_stdin_does_not_leak_in_cmdline
PASS [ 0.109s] pdftract-core::TH-07-ps-leak tests::test_password_env_var_does_not_leak_in_cmdline
Summary: 7 tests run: 7 passed, 0 skipped
Implementation Notes
- The test validates CLI-level password handling, which happens before PDF decryption
- Uses a minimal unencrypted PDF as fixture since password rejection occurs at argument parsing
- The
/proc/<pid>/cmdlinetests use a retry loop to handle race conditions with fast-exiting processes - Tests run on all platforms; Linux-specific tests are gated with
#[cfg(target_os = "linux")]
References
- Plan: line 878 (TH-07 entry)
- Depends on: pdftract-2ka7 (--password-stdin + PDFTRACT_PASSWORD hardening)