First off, thank you for considering contributing to PySpector! We're excited to have you. Every contribution, whether it's a new feature, a bug fix, or a new rule, helps us make Python code, safer for everyone.
This document provides a simple guide to get you started.
There are many ways you can contribute to the project:
- Reporting Bugs: If you find something that isn't working as expected, please open an issue.
- Suggesting Enhancements: Have an idea for a new feature or a way to improve an existing one? We'd love to hear it.
- Writing New Rules: The heart of PySpector is its ruleset. Adding new rules to detect vulnerabilities is one of the most valuable ways to contribute.
- Improving the Code: If you see an opportunity to improve the Python or Rust code, feel free to submit a PR.
To get the project running on your local machine, you'll need to set up a few things.
- Python: You'll need Python 3.8 or newer (recommended Python3.12).
- Rust: The core engine of PySpector is written in Rust. The best way to install it is via rustup.
-
Fork Pyspector and Clone your Repository:
git clone https://github.com/YOURUSERNAME/PySpector.git cd PySpector -
Create a Python3.12 Virtual Environment:
python3.12 -m venv venvname
Then:
source venvname/bin/activate
or, if on Windows:
.\venvname\Bin\Activate.ps1
-
Install the Project in Editable Mode: This is the most important step. This command will compile the Rust engine and install the Python package in a way that lets you make changes without reinstalling.
pip install -e . -
Run it!: You should now be able to run PySpector directly.
pyspector --help
Adding a new rule is a great way to make a big impact. Rules are defined in the .toml files located in src/pyspector/rules/.
- Simple Regex Rules: For rules that can be found with a simple text search, you can add a new
[[rule]]tobuilt-in-rules.toml. Just define apatternusing a regular expression. - AST-Based Rules: For more complex rules that need to understand the code's structure, you can define an
ast_matchpattern. This allows you to target specific Python AST nodes, like function calls with certain arguments. - Taint Analysis Rules: To track the flow of untrusted data, you can define new
[[taint_source]]or[[taint_sink]]rules.
When adding a new rule, please include a clear description, a severity level, and helpful remediation advice.
PySpector rules define what the engine looks for during analysis. Each rule describes a pattern or behavior that represents a potential security issue.
A rule typically consists of:
- Metadata (name, severity, description)
- A matcher or condition
- A message explaining the issue
Rules are loaded at runtime and applied uniformly across the scanned codebase.
Below is a minimal conceptual example of a rule:
file_pattern = "*.py"
[[rule]]
id = "PY200"
description = "Use of 'eval' detected."
severity = "High"
remediation = "Avoid using eval(). Use safer alternatives like ast.literal_eval or explicit parsing."
ast_match = "Call(func.id=eval)"Ready to submit your changes? Just follow these steps:
- Create a new branch for your feature or bug fix.
git checkout -b my-new-rule
- Make your changes and commit them with a clear message.
git commit -m "feat: Add new rule to detect insecure cookie settings" - Push your branch to your fork.
git push origin my-new-rule
- Open a Pull Request on the main PySpector repository. Please provide a clear description of what you've done.
We'll review your contribution as soon as we can. Thank you again for considering helping to improve PySpector!
