pyshield-security 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyshield_security-0.1.0/.gitignore +68 -0
- pyshield_security-0.1.0/.python-version +1 -0
- pyshield_security-0.1.0/CHANGELOG.md +34 -0
- pyshield_security-0.1.0/CODE_OF_CONDUCT.md +35 -0
- pyshield_security-0.1.0/CONTRIBUTING.md +56 -0
- pyshield_security-0.1.0/LICENSE +21 -0
- pyshield_security-0.1.0/PKG-INFO +212 -0
- pyshield_security-0.1.0/README.md +185 -0
- pyshield_security-0.1.0/SECURITY.md +32 -0
- pyshield_security-0.1.0/docs/README.md +4 -0
- pyshield_security-0.1.0/examples/README.md +3 -0
- pyshield_security-0.1.0/pyproject.toml +98 -0
- pyshield_security-0.1.0/scripts/check.py +24 -0
- pyshield_security-0.1.0/src/pyshield/__init__.py +4 -0
- pyshield_security-0.1.0/src/pyshield/__main__.py +8 -0
- pyshield_security-0.1.0/src/pyshield/cli/__init__.py +5 -0
- pyshield_security-0.1.0/src/pyshield/cli/main.py +115 -0
- pyshield_security-0.1.0/src/pyshield/config/__init__.py +5 -0
- pyshield_security-0.1.0/src/pyshield/config/models.py +54 -0
- pyshield_security-0.1.0/src/pyshield/core/__init__.py +19 -0
- pyshield_security-0.1.0/src/pyshield/core/analyzer.py +77 -0
- pyshield_security-0.1.0/src/pyshield/core/engine.py +165 -0
- pyshield_security-0.1.0/src/pyshield/core/models.py +117 -0
- pyshield_security-0.1.0/src/pyshield/core/registry.py +65 -0
- pyshield_security-0.1.0/src/pyshield/reporters/__init__.py +5 -0
- pyshield_security-0.1.0/src/pyshield/reporters/terminal.py +83 -0
- pyshield_security-0.1.0/src/pyshield/rules/__init__.py +32 -0
- pyshield_security-0.1.0/src/pyshield/rules/base.py +118 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/__init__.py +43 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/api_token.py +106 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/dangerous_eval.py +45 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/dangerous_exec.py +45 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/hardcoded_secret.py +151 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/insecure_crypto.py +101 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/insecure_random.py +133 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/os_system.py +61 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/private_key.py +52 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/unsafe_subprocess.py +101 -0
- pyshield_security-0.1.0/src/pyshield/rules/builtin/weak_hash.py +94 -0
- pyshield_security-0.1.0/src/pyshield/rules/secrets_utils.py +166 -0
- pyshield_security-0.1.0/tests/__init__.py +1 -0
- pyshield_security-0.1.0/tests/conftest.py +20 -0
- pyshield_security-0.1.0/tests/fixtures/benign/clean_code.py +66 -0
- pyshield_security-0.1.0/tests/fixtures/syntax_error/broken.py +5 -0
- pyshield_security-0.1.0/tests/fixtures/vulnerable/sample_vulns.py +54 -0
- pyshield_security-0.1.0/tests/integration/test_cli.py +107 -0
- pyshield_security-0.1.0/tests/integration/test_discovery.py +63 -0
- pyshield_security-0.1.0/tests/unit/rules/test_api_token.py +189 -0
- pyshield_security-0.1.0/tests/unit/rules/test_dangerous_eval.py +78 -0
- pyshield_security-0.1.0/tests/unit/rules/test_dangerous_exec.py +78 -0
- pyshield_security-0.1.0/tests/unit/rules/test_hardcoded_secret.py +152 -0
- pyshield_security-0.1.0/tests/unit/rules/test_insecure_crypto.py +95 -0
- pyshield_security-0.1.0/tests/unit/rules/test_insecure_random.py +87 -0
- pyshield_security-0.1.0/tests/unit/rules/test_os_system.py +85 -0
- pyshield_security-0.1.0/tests/unit/rules/test_private_key.py +119 -0
- pyshield_security-0.1.0/tests/unit/rules/test_unsafe_subprocess.py +129 -0
- pyshield_security-0.1.0/tests/unit/rules/test_weak_hash.py +90 -0
- pyshield_security-0.1.0/tests/unit/test_analyzer.py +55 -0
- pyshield_security-0.1.0/tests/unit/test_engine.py +89 -0
- pyshield_security-0.1.0/tests/unit/test_models.py +86 -0
- pyshield_security-0.1.0/tests/unit/test_registry.py +69 -0
- pyshield_security-0.1.0/tests/unit/test_reporters.py +83 -0
- pyshield_security-0.1.0/tests/unit/test_secrets_utils.py +97 -0
- pyshield_security-0.1.0/uv.lock +785 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
*.manifest
|
|
31
|
+
*.spec
|
|
32
|
+
|
|
33
|
+
# Unit test / coverage
|
|
34
|
+
htmlcov/
|
|
35
|
+
.tox/
|
|
36
|
+
.nox/
|
|
37
|
+
.coverage
|
|
38
|
+
.coverage.*
|
|
39
|
+
.cache
|
|
40
|
+
nosetests.xml
|
|
41
|
+
coverage.xml
|
|
42
|
+
*.cover
|
|
43
|
+
*.py,cover
|
|
44
|
+
.hypothesis/
|
|
45
|
+
.pytest_cache/
|
|
46
|
+
|
|
47
|
+
# Environments
|
|
48
|
+
.env
|
|
49
|
+
.venv
|
|
50
|
+
env/
|
|
51
|
+
venv/
|
|
52
|
+
ENV/
|
|
53
|
+
env.bak/
|
|
54
|
+
venv.bak/
|
|
55
|
+
|
|
56
|
+
# Code quality
|
|
57
|
+
.ruff_cache/
|
|
58
|
+
.mypy_cache/
|
|
59
|
+
|
|
60
|
+
# IDEs
|
|
61
|
+
.vscode/
|
|
62
|
+
.idea/
|
|
63
|
+
*.swp
|
|
64
|
+
*.swo
|
|
65
|
+
|
|
66
|
+
# OS
|
|
67
|
+
.DS_Store
|
|
68
|
+
Thumbs.db
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-09-06
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Core Static Security Analysis Engine**:
|
|
12
|
+
- Deterministic Python `ast`-based analyzer with graceful syntax error and decode recovery.
|
|
13
|
+
- Safe recursive file discovery respecting ignore patterns (`.git`, `.venv`, `__pycache__`) and symlink cycles.
|
|
14
|
+
- Extensible `RuleRegistry` and `BaseRule` architecture.
|
|
15
|
+
- Decoupled terminal reporting using `rich`.
|
|
16
|
+
- Developer-friendly CLI via `typer` (`pyshield scan`, `pyshield --version`).
|
|
17
|
+
- Standardized exit codes (`0` clean, `1` findings detected, `2` fatal error).
|
|
18
|
+
- **Execution & Injection Security Rules (Phase 1)**:
|
|
19
|
+
- `PS101`: Dangerous `eval()` usage detection (CWE-95).
|
|
20
|
+
- `PS102`: Dangerous `exec()` usage detection (CWE-95).
|
|
21
|
+
- `PS103`: Dangerous `os.system()` usage detection (CWE-78).
|
|
22
|
+
- `PS104`: Unsafe `subprocess` execution with `shell=True` (CWE-78).
|
|
23
|
+
- **Secret Detection & Cryptography Analysis Rules (Phase 2)**:
|
|
24
|
+
- `PS201`: Hardcoded Secret / Credential detection with contextual identifier matching, Shannon entropy analysis, and placeholder filtering.
|
|
25
|
+
- `PS202`: Private Key Material detection for RSA, EC, DSA, and OpenSSH private key PEM blocks.
|
|
26
|
+
- `PS203`: High-confidence API Token detection with specific patterns for AWS, GitHub (classic and fine-grained PATs), Slack, Google, and Stripe.
|
|
27
|
+
- `PS301`: Weak Cryptographic Hash detection for MD5 and SHA-1 via `hashlib` (properly exempts `usedforsecurity=False`).
|
|
28
|
+
- `PS302`: Insecure Cryptographic Algorithm detection for broken legacy ciphers (DES, 3DES, Blowfish, ARC4) across `cryptography` and `Crypto.Cipher`.
|
|
29
|
+
- `PS303`: Insecure Randomness detection for pseudo-random standard library `random` module usage in security-sensitive scopes (tokens, passwords, keys, salts).
|
|
30
|
+
- Shared secrets utility module (`secrets_utils.py`) with Shannon entropy, placeholder recognition, and sensitive token masking.
|
|
31
|
+
- Strict secret leakage prevention guaranteeing detected secrets never appear in finding messages, descriptions, snippets, logs, or terminal reports.
|
|
32
|
+
- **Testing & Quality**:
|
|
33
|
+
- Complete test suite with 155 unit and integration tests achieving >94% line coverage.
|
|
34
|
+
- Strict typing (Mypy strict mode) and Ruff linting/formatting.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
+
|
|
9
|
+
## Our Standards
|
|
10
|
+
|
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
+
* Demonstrating empathy and kindness toward other people
|
|
13
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
14
|
+
* Giving and gracefully accepting constructive feedback
|
|
15
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
|
16
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
|
17
|
+
|
|
18
|
+
Examples of unacceptable behavior include:
|
|
19
|
+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
|
|
20
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
21
|
+
* Public or private harassment
|
|
22
|
+
* Publishing others' private information without explicit permission
|
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
24
|
+
|
|
25
|
+
## Enforcement Responsibilities
|
|
26
|
+
|
|
27
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
28
|
+
|
|
29
|
+
## Scope
|
|
30
|
+
|
|
31
|
+
This Code of Conduct applies within all project spaces, and also applies when an individual is representing the project or its community in public spaces.
|
|
32
|
+
|
|
33
|
+
## Contact
|
|
34
|
+
|
|
35
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leadership at `conduct@zn-forge.org`. All complaints will be reviewed and investigated promptly and fairly.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Contributing to PyShield
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to PyShield!
|
|
4
|
+
|
|
5
|
+
PyShield is an open-source security analysis platform maintained under the **ZN-Forge** organization. We welcome contributions from developers of all backgrounds.
|
|
6
|
+
|
|
7
|
+
## Development Principles
|
|
8
|
+
|
|
9
|
+
1. **Deterministic-first**: Security rules must be deterministic, accurate, and have minimal false positives.
|
|
10
|
+
2. **Local-first & Privacy-conscious**: Source code must never leave the local environment by default.
|
|
11
|
+
3. **Core Decoupling**: Core analysis must remain completely decoupled from presentation, API, and database layers.
|
|
12
|
+
4. **Minimal Dependencies**: Do not add dependencies unless strictly required.
|
|
13
|
+
5. **Rigorous Quality**: Every new feature or rule must include unit tests, type annotations, and pass all quality gates.
|
|
14
|
+
|
|
15
|
+
## Development Setup
|
|
16
|
+
|
|
17
|
+
We use [`uv`](https://docs.astral.sh/uv/) for project and dependency management.
|
|
18
|
+
|
|
19
|
+
### 1. Clone the repository
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/ZN-Forge/pyshield.git
|
|
22
|
+
cd pyshield
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Set up isolated environment
|
|
26
|
+
```bash
|
|
27
|
+
uv sync
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This creates a local `.venv/` and installs all runtime and development dependencies locked in `uv.lock`.
|
|
31
|
+
|
|
32
|
+
### 3. Run Quality Gates
|
|
33
|
+
Before submitting a PR, make sure all quality checks pass:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Run tests with coverage
|
|
37
|
+
uv run pytest --cov=pyshield --cov-report=term-missing
|
|
38
|
+
|
|
39
|
+
# Run linter
|
|
40
|
+
uv run ruff check .
|
|
41
|
+
|
|
42
|
+
# Run code formatter check
|
|
43
|
+
uv run ruff format --check .
|
|
44
|
+
|
|
45
|
+
# Run type checker
|
|
46
|
+
uv run mypy src
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Adding a Security Rule
|
|
50
|
+
|
|
51
|
+
When contributing a new rule:
|
|
52
|
+
1. Choose an appropriate ID (e.g., `PS1xx` for Execution/Injection).
|
|
53
|
+
2. Implement the rule in `src/pyshield/rules/builtin/` inheriting from `BaseRule`.
|
|
54
|
+
3. Provide comprehensive positive tests (detect vulnerable pattern), negative tests (safe patterns), and edge cases (avoiding false positives).
|
|
55
|
+
4. Register the rule in `src/pyshield/core/registry.py`.
|
|
56
|
+
5. Update documentation and rule references.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ZN-Forge
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pyshield-security
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open-source developer-focused security analysis platform for Python projects.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ZN-Forge/pyshield
|
|
6
|
+
Project-URL: Repository, https://github.com/ZN-Forge/pyshield
|
|
7
|
+
Project-URL: Issues, https://github.com/ZN-Forge/pyshield/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/ZN-Forge/pyshield#readme
|
|
9
|
+
Author-email: ZN-Forge <oss@zn-forge.org>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ast,pyshield,pyshield-security,scanner,security,static-analysis,vulnerability
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: pydantic>=2.7.0
|
|
24
|
+
Requires-Dist: rich>=13.7.0
|
|
25
|
+
Requires-Dist: typer>=0.12.0
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# PyShield
|
|
29
|
+
|
|
30
|
+
[](https://github.com/ZN-Forge/pyshield/actions/workflows/ci.yml)
|
|
31
|
+
[](https://pypi.org/project/pyshield-security/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
[](https://www.python.org/)
|
|
34
|
+
[](https://docs.astral.sh/uv/)
|
|
35
|
+
|
|
36
|
+
**PyShield** is a developer-focused, open-source static security analysis platform for Python projects, maintained under the [**ZN-Forge**](https://github.com/ZN-Forge) organization.
|
|
37
|
+
|
|
38
|
+
Its primary purpose is to help developers identify potential security vulnerabilities in their code before reaching production through fast, deterministic AST analysis.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
> [!NOTE]
|
|
43
|
+
> **Current Status: Version 0.1.0 (Core Engine, Injection, Secrets & Cryptography)**
|
|
44
|
+
> PyShield v0.1.0 provides a fast, deterministic static analysis engine, rule registry, code execution/injection rules, secret detection, and cryptography security analysis. All detected secrets are automatically masked in output to prevent sensitive data leakage. Future capabilities (SARIF export, dependency scanning, React UI, etc.) are planned for upcoming releases.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Core Philosophy
|
|
49
|
+
|
|
50
|
+
1. **Deterministic-First**: Security detection is powered primarily by deterministic AST analysis and strict rules. Findings are verifiable and reproducible.
|
|
51
|
+
2. **Local-First & Privacy-Focused**: Source code is analyzed entirely on your local machine and is never transmitted to external services.
|
|
52
|
+
3. **Secret Protection by Design**: Detected secret values and key material are masked in terminal reports and findings to prevent credential exposure.
|
|
53
|
+
4. **Core Decoupling**: The static security analysis engine is strictly decoupled from presentation, web server, and persistence layers.
|
|
54
|
+
5. **Minimal Dependencies**: The core analysis leverages Python's built-in `ast` standard library to remain fast, lightweight, and maintainable.
|
|
55
|
+
6. **Zero False-Positive Focus**: Rules are designed conservatively to highlight high-confidence security hazards without flooding developers with noise.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Supported Rules
|
|
60
|
+
|
|
61
|
+
### Execution & Code Injection (Phase 1)
|
|
62
|
+
| Rule ID | Name | Severity | CWE | Description |
|
|
63
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
64
|
+
| **`PS101`** | Dangerous `eval()` usage | `CRITICAL` | CWE-95 | Detects calls to built-in `eval()`, preventing dynamic code execution risks. |
|
|
65
|
+
| **`PS102`** | Dangerous `exec()` usage | `CRITICAL` | CWE-95 | Detects calls to built-in `exec()`, preventing dynamic statement execution vulnerabilities. |
|
|
66
|
+
| **`PS103`** | Use of `os.system()` | `HIGH` | CWE-78 | Detects calls to `os.system()` which execute commands via shell strings. |
|
|
67
|
+
| **`PS104`** | Unsafe `subprocess` execution | `HIGH` | CWE-78 | Detects subprocess execution calls configured with `shell=True`. |
|
|
68
|
+
|
|
69
|
+
### Secret & Key Material Detection (Phase 2)
|
|
70
|
+
| Rule ID | Name | Severity | CWE | Description |
|
|
71
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
72
|
+
| **`PS201`** | Hardcoded Secret / Credential | `HIGH` | CWE-798 | Detects hardcoded passwords, tokens, secrets, and API keys with entropy filtering and placeholder exclusion. |
|
|
73
|
+
| **`PS202`** | Private Key Material | `CRITICAL` | CWE-321 | Detects hardcoded RSA, EC, DSA, and OpenSSH private key PEM headers and content. |
|
|
74
|
+
| **`PS203`** | High-Confidence API Token | `HIGH` | CWE-798 | Detects provider-specific tokens (AWS, GitHub classic/fine-grained, Slack, Google, Stripe) using strict patterns. |
|
|
75
|
+
|
|
76
|
+
### Cryptographic Analysis (Phase 2)
|
|
77
|
+
| Rule ID | Name | Severity | CWE | Description |
|
|
78
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
79
|
+
| **`PS301`** | Weak Hash Algorithm | `MEDIUM` | CWE-328 | Detects insecure MD5 and SHA-1 hashing via `hashlib` (exempts `usedforsecurity=False`). |
|
|
80
|
+
| **`PS302`** | Insecure Cryptographic Algorithm | `HIGH` | CWE-327 | Detects broken legacy ciphers (DES, 3DES, Blowfish, ARC4) in `cryptography` and PyCryptodome. |
|
|
81
|
+
| **`PS303`** | Insecure Randomness | `HIGH` | CWE-338 | Detects use of standard pseudo-random `random` module in security-sensitive contexts (tokens, salts, keys, auth). |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
PyShield can be installed from PyPI using `pip` or `uv`:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Using pip
|
|
91
|
+
pip install pyshield-security
|
|
92
|
+
|
|
93
|
+
# Using uv
|
|
94
|
+
uv add pyshield-security
|
|
95
|
+
|
|
96
|
+
# Or as a global CLI tool using uv:
|
|
97
|
+
uv tool install pyshield-security
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> [!NOTE]
|
|
101
|
+
> The PyPI distribution package name is **`pyshield-security`**. The command-line command is **`pyshield`**, and the Python import package is **`pyshield`**:
|
|
102
|
+
> ```bash
|
|
103
|
+
> pyshield --version
|
|
104
|
+
> ```
|
|
105
|
+
> ```python
|
|
106
|
+
> import pyshield
|
|
107
|
+
> ```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Development Setup
|
|
112
|
+
|
|
113
|
+
For local development or contributing, clone the repository and synchronize the isolated virtual environment using [`uv`](https://docs.astral.sh/uv/):
|
|
114
|
+
|
|
115
|
+
### Prerequisites
|
|
116
|
+
- Python 3.11 or higher
|
|
117
|
+
- `uv` package manager
|
|
118
|
+
|
|
119
|
+
### Setup
|
|
120
|
+
```bash
|
|
121
|
+
git clone https://github.com/ZN-Forge/pyshield.git
|
|
122
|
+
cd pyshield
|
|
123
|
+
uv sync
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This creates a project-local `.venv/` containing all runtime and development dependencies locked in `uv.lock`.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## CLI Usage
|
|
131
|
+
|
|
132
|
+
### Check Version
|
|
133
|
+
```bash
|
|
134
|
+
# Direct CLI command (if installed via pip or uv tool):
|
|
135
|
+
pyshield --version
|
|
136
|
+
|
|
137
|
+
# Or inside the local development environment:
|
|
138
|
+
uv run pyshield --version
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Scan Current Directory
|
|
142
|
+
```bash
|
|
143
|
+
uv run pyshield scan .
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Scan Specific Directory or File
|
|
147
|
+
```bash
|
|
148
|
+
uv run pyshield scan src/
|
|
149
|
+
uv run pyshield scan app/main.py
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### CLI Options
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
Usage: pyshield scan [OPTIONS] [PATHS]...
|
|
156
|
+
|
|
157
|
+
Arguments:
|
|
158
|
+
[PATHS]... One or more paths to scan (default: current directory)
|
|
159
|
+
|
|
160
|
+
Options:
|
|
161
|
+
--fail-on [LOW|MEDIUM|HIGH|CRITICAL]
|
|
162
|
+
Minimum severity to trigger non-zero exit code [default: LOW]
|
|
163
|
+
-e, --exclude TEXT Additional glob patterns or directories to exclude
|
|
164
|
+
-d, --disable-rule TEXT Rule ID to disable (e.g. -d PS101)
|
|
165
|
+
--enable-rule TEXT Explicit rule ID to run (e.g. --enable-rule PS103)
|
|
166
|
+
--help Show help message and exit
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Exit Codes
|
|
170
|
+
- `0`: Scan completed successfully; no findings at or above configured failure threshold.
|
|
171
|
+
- `1`: Security findings detected at or above configured failure threshold.
|
|
172
|
+
- `2`: Fatal error (target path not found, or all target files failed parsing).
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Development & Quality Gates
|
|
177
|
+
|
|
178
|
+
PyShield enforces strict quality gates before any code is merged:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Run tests with coverage
|
|
182
|
+
uv run pytest --cov=pyshield --cov-report=term-missing
|
|
183
|
+
|
|
184
|
+
# Run Ruff linter
|
|
185
|
+
uv run ruff check .
|
|
186
|
+
|
|
187
|
+
# Run Ruff format check
|
|
188
|
+
uv run ruff format --check .
|
|
189
|
+
|
|
190
|
+
# Run strict type checking
|
|
191
|
+
uv run mypy src
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Planned Architecture (Future Phases)
|
|
197
|
+
|
|
198
|
+
The following capabilities are deliberately planned for subsequent phases:
|
|
199
|
+
|
|
200
|
+
- **Phase 1 (Completed)**: Core static analysis engine, rule registry, injection rules (`PS101`–`PS104`), CLI, and terminal reporter.
|
|
201
|
+
- **Phase 2 (Completed)**: Secret detection engine (`PS201`–`PS203`) and Cryptography rules (`PS301`–`PS303`) with zero leakage protection.
|
|
202
|
+
- **Phase 3+**: Dependency vulnerability scanning (`PS8xx`) and Framework-specific rules (Django, FastAPI, Flask).
|
|
203
|
+
- **Phase 4+**: Standard SARIF, JSON, and Markdown export formats.
|
|
204
|
+
- **Phase 5+**: Optional Local AI analysis layer (via Ollama / llama.cpp) to explain and contextualize deterministic findings.
|
|
205
|
+
- **Phase 6+**: Local Web UI (React + TypeScript + Vite + Tailwind CSS) with FastAPI backend and SQLite persistence.
|
|
206
|
+
- **Phase 7+**: Comprehensive product/documentation website on GitHub Pages and contributor ecosystem.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# PyShield
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ZN-Forge/pyshield/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/pyshield-security/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.python.org/)
|
|
7
|
+
[](https://docs.astral.sh/uv/)
|
|
8
|
+
|
|
9
|
+
**PyShield** is a developer-focused, open-source static security analysis platform for Python projects, maintained under the [**ZN-Forge**](https://github.com/ZN-Forge) organization.
|
|
10
|
+
|
|
11
|
+
Its primary purpose is to help developers identify potential security vulnerabilities in their code before reaching production through fast, deterministic AST analysis.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
> [!NOTE]
|
|
16
|
+
> **Current Status: Version 0.1.0 (Core Engine, Injection, Secrets & Cryptography)**
|
|
17
|
+
> PyShield v0.1.0 provides a fast, deterministic static analysis engine, rule registry, code execution/injection rules, secret detection, and cryptography security analysis. All detected secrets are automatically masked in output to prevent sensitive data leakage. Future capabilities (SARIF export, dependency scanning, React UI, etc.) are planned for upcoming releases.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Core Philosophy
|
|
22
|
+
|
|
23
|
+
1. **Deterministic-First**: Security detection is powered primarily by deterministic AST analysis and strict rules. Findings are verifiable and reproducible.
|
|
24
|
+
2. **Local-First & Privacy-Focused**: Source code is analyzed entirely on your local machine and is never transmitted to external services.
|
|
25
|
+
3. **Secret Protection by Design**: Detected secret values and key material are masked in terminal reports and findings to prevent credential exposure.
|
|
26
|
+
4. **Core Decoupling**: The static security analysis engine is strictly decoupled from presentation, web server, and persistence layers.
|
|
27
|
+
5. **Minimal Dependencies**: The core analysis leverages Python's built-in `ast` standard library to remain fast, lightweight, and maintainable.
|
|
28
|
+
6. **Zero False-Positive Focus**: Rules are designed conservatively to highlight high-confidence security hazards without flooding developers with noise.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Supported Rules
|
|
33
|
+
|
|
34
|
+
### Execution & Code Injection (Phase 1)
|
|
35
|
+
| Rule ID | Name | Severity | CWE | Description |
|
|
36
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
37
|
+
| **`PS101`** | Dangerous `eval()` usage | `CRITICAL` | CWE-95 | Detects calls to built-in `eval()`, preventing dynamic code execution risks. |
|
|
38
|
+
| **`PS102`** | Dangerous `exec()` usage | `CRITICAL` | CWE-95 | Detects calls to built-in `exec()`, preventing dynamic statement execution vulnerabilities. |
|
|
39
|
+
| **`PS103`** | Use of `os.system()` | `HIGH` | CWE-78 | Detects calls to `os.system()` which execute commands via shell strings. |
|
|
40
|
+
| **`PS104`** | Unsafe `subprocess` execution | `HIGH` | CWE-78 | Detects subprocess execution calls configured with `shell=True`. |
|
|
41
|
+
|
|
42
|
+
### Secret & Key Material Detection (Phase 2)
|
|
43
|
+
| Rule ID | Name | Severity | CWE | Description |
|
|
44
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
45
|
+
| **`PS201`** | Hardcoded Secret / Credential | `HIGH` | CWE-798 | Detects hardcoded passwords, tokens, secrets, and API keys with entropy filtering and placeholder exclusion. |
|
|
46
|
+
| **`PS202`** | Private Key Material | `CRITICAL` | CWE-321 | Detects hardcoded RSA, EC, DSA, and OpenSSH private key PEM headers and content. |
|
|
47
|
+
| **`PS203`** | High-Confidence API Token | `HIGH` | CWE-798 | Detects provider-specific tokens (AWS, GitHub classic/fine-grained, Slack, Google, Stripe) using strict patterns. |
|
|
48
|
+
|
|
49
|
+
### Cryptographic Analysis (Phase 2)
|
|
50
|
+
| Rule ID | Name | Severity | CWE | Description |
|
|
51
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
52
|
+
| **`PS301`** | Weak Hash Algorithm | `MEDIUM` | CWE-328 | Detects insecure MD5 and SHA-1 hashing via `hashlib` (exempts `usedforsecurity=False`). |
|
|
53
|
+
| **`PS302`** | Insecure Cryptographic Algorithm | `HIGH` | CWE-327 | Detects broken legacy ciphers (DES, 3DES, Blowfish, ARC4) in `cryptography` and PyCryptodome. |
|
|
54
|
+
| **`PS303`** | Insecure Randomness | `HIGH` | CWE-338 | Detects use of standard pseudo-random `random` module in security-sensitive contexts (tokens, salts, keys, auth). |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
PyShield can be installed from PyPI using `pip` or `uv`:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Using pip
|
|
64
|
+
pip install pyshield-security
|
|
65
|
+
|
|
66
|
+
# Using uv
|
|
67
|
+
uv add pyshield-security
|
|
68
|
+
|
|
69
|
+
# Or as a global CLI tool using uv:
|
|
70
|
+
uv tool install pyshield-security
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> [!NOTE]
|
|
74
|
+
> The PyPI distribution package name is **`pyshield-security`**. The command-line command is **`pyshield`**, and the Python import package is **`pyshield`**:
|
|
75
|
+
> ```bash
|
|
76
|
+
> pyshield --version
|
|
77
|
+
> ```
|
|
78
|
+
> ```python
|
|
79
|
+
> import pyshield
|
|
80
|
+
> ```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Development Setup
|
|
85
|
+
|
|
86
|
+
For local development or contributing, clone the repository and synchronize the isolated virtual environment using [`uv`](https://docs.astral.sh/uv/):
|
|
87
|
+
|
|
88
|
+
### Prerequisites
|
|
89
|
+
- Python 3.11 or higher
|
|
90
|
+
- `uv` package manager
|
|
91
|
+
|
|
92
|
+
### Setup
|
|
93
|
+
```bash
|
|
94
|
+
git clone https://github.com/ZN-Forge/pyshield.git
|
|
95
|
+
cd pyshield
|
|
96
|
+
uv sync
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This creates a project-local `.venv/` containing all runtime and development dependencies locked in `uv.lock`.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## CLI Usage
|
|
104
|
+
|
|
105
|
+
### Check Version
|
|
106
|
+
```bash
|
|
107
|
+
# Direct CLI command (if installed via pip or uv tool):
|
|
108
|
+
pyshield --version
|
|
109
|
+
|
|
110
|
+
# Or inside the local development environment:
|
|
111
|
+
uv run pyshield --version
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Scan Current Directory
|
|
115
|
+
```bash
|
|
116
|
+
uv run pyshield scan .
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Scan Specific Directory or File
|
|
120
|
+
```bash
|
|
121
|
+
uv run pyshield scan src/
|
|
122
|
+
uv run pyshield scan app/main.py
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### CLI Options
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
Usage: pyshield scan [OPTIONS] [PATHS]...
|
|
129
|
+
|
|
130
|
+
Arguments:
|
|
131
|
+
[PATHS]... One or more paths to scan (default: current directory)
|
|
132
|
+
|
|
133
|
+
Options:
|
|
134
|
+
--fail-on [LOW|MEDIUM|HIGH|CRITICAL]
|
|
135
|
+
Minimum severity to trigger non-zero exit code [default: LOW]
|
|
136
|
+
-e, --exclude TEXT Additional glob patterns or directories to exclude
|
|
137
|
+
-d, --disable-rule TEXT Rule ID to disable (e.g. -d PS101)
|
|
138
|
+
--enable-rule TEXT Explicit rule ID to run (e.g. --enable-rule PS103)
|
|
139
|
+
--help Show help message and exit
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Exit Codes
|
|
143
|
+
- `0`: Scan completed successfully; no findings at or above configured failure threshold.
|
|
144
|
+
- `1`: Security findings detected at or above configured failure threshold.
|
|
145
|
+
- `2`: Fatal error (target path not found, or all target files failed parsing).
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Development & Quality Gates
|
|
150
|
+
|
|
151
|
+
PyShield enforces strict quality gates before any code is merged:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Run tests with coverage
|
|
155
|
+
uv run pytest --cov=pyshield --cov-report=term-missing
|
|
156
|
+
|
|
157
|
+
# Run Ruff linter
|
|
158
|
+
uv run ruff check .
|
|
159
|
+
|
|
160
|
+
# Run Ruff format check
|
|
161
|
+
uv run ruff format --check .
|
|
162
|
+
|
|
163
|
+
# Run strict type checking
|
|
164
|
+
uv run mypy src
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Planned Architecture (Future Phases)
|
|
170
|
+
|
|
171
|
+
The following capabilities are deliberately planned for subsequent phases:
|
|
172
|
+
|
|
173
|
+
- **Phase 1 (Completed)**: Core static analysis engine, rule registry, injection rules (`PS101`–`PS104`), CLI, and terminal reporter.
|
|
174
|
+
- **Phase 2 (Completed)**: Secret detection engine (`PS201`–`PS203`) and Cryptography rules (`PS301`–`PS303`) with zero leakage protection.
|
|
175
|
+
- **Phase 3+**: Dependency vulnerability scanning (`PS8xx`) and Framework-specific rules (Django, FastAPI, Flask).
|
|
176
|
+
- **Phase 4+**: Standard SARIF, JSON, and Markdown export formats.
|
|
177
|
+
- **Phase 5+**: Optional Local AI analysis layer (via Ollama / llama.cpp) to explain and contextualize deterministic findings.
|
|
178
|
+
- **Phase 6+**: Local Web UI (React + TypeScript + Vite + Tailwind CSS) with FastAPI backend and SQLite persistence.
|
|
179
|
+
- **Phase 7+**: Comprehensive product/documentation website on GitHub Pages and contributor ecosystem.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
PyShield takes security seriously. Security updates are applied to the active development version.
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | ------------------ |
|
|
9
|
+
| 0.1.x | :white_check_mark: |
|
|
10
|
+
|
|
11
|
+
## Reporting a Vulnerability
|
|
12
|
+
|
|
13
|
+
If you discover a security vulnerability within PyShield, please report it responsibly.
|
|
14
|
+
|
|
15
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
16
|
+
|
|
17
|
+
Instead, please report security issues via GitHub Private Vulnerability Reporting on the repository, or by emailing the maintainers at:
|
|
18
|
+
|
|
19
|
+
`security@zn-forge.org`
|
|
20
|
+
|
|
21
|
+
Include as much of the following details as possible:
|
|
22
|
+
- Description of the vulnerability and its potential impact
|
|
23
|
+
- Steps to reproduce the vulnerability (proof of concept code or configuration)
|
|
24
|
+
- Environment details (Python version, PyShield version, OS)
|
|
25
|
+
- Any proposed remediation or mitigations
|
|
26
|
+
|
|
27
|
+
## Response Process
|
|
28
|
+
|
|
29
|
+
1. You will receive an acknowledgment of your report within 48 hours.
|
|
30
|
+
2. The PyShield maintainers will evaluate the report and verify the issue.
|
|
31
|
+
3. If confirmed, a fix will be prepared in a private fork and tested thoroughly.
|
|
32
|
+
4. A patched release will be issued alongside a public security advisory crediting the reporter (if desired).
|