Contributing to pdf-defang¶
Thanks for taking the time to contribute! This project is small and focused, which makes it easy to contribute meaningfully even with a small change.
Quick links¶
- Issues - bug reports and feature requests
- Security - for security vulnerabilities, please do NOT open a public issue
- Changelog - what's changed
- Email: contact@kovetz.co.il
Ways to help¶
Reporting bugs¶
If you've found a PDF that contains active content pdf-defang doesn't
strip, that's a high-priority bug for us. Please open a GitHub issue with:
- A description of what's wrong
- The actual PDF file (or a minimal reproducer that demonstrates the issue)
- The output of
pdf-defang scan <file> --jsonon that file - The version of
pdf-defangandpikepdf(pip show pdf-defang pikepdf)
If the PDF contains sensitive content, see SECURITY.md for how to share it privately.
Suggesting features¶
Open a GitHub issue with the use case. We're particularly interested in:
- PDF action types we don't currently strip
- Edge cases in URI scheme detection
- Patterns common in PDF malware that we miss
- Integration suggestions (logging frameworks, web frameworks, etc.)
What we'd push back on:
- Visual content analysis (rendering PDFs, looking at images) - out of scope
- Anything that requires a heavy dependency (numpy, machine learning, etc.)
- Plugins/extension points without a clear use case
Code contributions¶
Setup¶
git clone https://github.com/kovetz-PDF/pdf-defang.git
cd pdf-defang
python -m pip install -e ".[test]"
python -m pytest
The test suite auto-generates fixture PDFs on first run, so the first
pytest invocation is slower than subsequent ones.
Style¶
We use:
rufffor lint and formatting:python -m ruff check pdf_defang/ tests/mypy --strictfor type checking:python -m mypy pdf_defang/ --strict --ignore-missing-importspytestfor tests (withpytest-covfor coverage)
All three must pass before merging. CI will check.
Adding a new dangerous content type¶
The most common contribution is "we should also strip X". Steps:
- Add the action/key to the appropriate constant in
pdf_defang/_core.py(e.g.,_DANGEROUS_ACTION_TYPES) - Update the matching detection in
pdf_defang/_scan.py - Create a fixture PDF in
tests/fixtures/generate_fixtures.pythat contains the new threat - Add tests in
tests/test_sanitize.pyandtests/test_scan.pythat verify both detection and removal - Update the relevant section of README.md
- Add an entry under "Unreleased" in CHANGELOG.md
Pull request checklist¶
- [ ] Tests pass (
python -m pytest) - [ ] Lint passes (
python -m ruff check) - [ ] Types pass (
python -m mypy --strict) - [ ] Coverage doesn't drop below 85%
- [ ] README updated if the public API changed
- [ ] CHANGELOG entry added
Code of Conduct¶
Be kind. We're all here to make the Python ecosystem a little safer. See CODE_OF_CONDUCT.md for the formal version (Contributor Covenant).