PuriPy Security Validator
A fast, comprehensive security validation system for Python code, designed to perform pre-execution security checks in cloud environments. This tool helps reduce costs and latency by validating code before spinning up sandbox VMs.
Overview
The PuriPy Security Validator provides a robust first line of defense for environments that execute arbitrary Python code. It performs quick security and syntax validation before committing resources to full sandbox execution, helping to:
- Reduce costs by catching issues before VM provisioning
- Minimize latency by failing fast on problematic code
- Prevent common security vulnerabilities
- Validate code structure and dependencies
Key Features
- Fast preliminary security validation
- Comprehensive static code analysis
- Multi-tool security scanning
- Parallel tool execution for speed
- Configurable security policies
- Dependency analysis and validation
- Support for popular data science libraries
- Detailed security reports
Architecture
The system consists of three main components:
-
FastSecurityAPI (
security_api.py)- Quick validation interface
- Security policy enforcement
- Execution policy decisions
-
CodeValidator (
security_validator.py)- Comprehensive code analysis
- External tool integration
- Parallel security scanning
- Detailed report generation
-
UnifiedSecurityVisitor (
security.py)- AST-based code analysis
- Security rule enforcement
- Vulnerability detection
Installation
pip install puripy
# Install required dependencies
pip install -r requirements.txt
If editing the package, install in editable mode:
git clone https://github.com/ndavidson19/PyPurify
pip install -e .
Usage
Basic Usage
from puripy import FastSecurityAPI
api = FastSecurityAPI()
result = api.validate_code(code)
print(f"Validation Result: {result.result}")
print(f"Message: {result.message}")
print(f"Execution Policy: {result.execution_policy}")
Command Line Usage
python security_validator.py path/to/code.py --json
Security Checks
The validator performs multiple levels of security checks:
1. Quick Checks
- Syntax validation
- Code size limits
- Blocked imports
- Dangerous function calls
- Known vulnerability patterns
2. Comprehensive Analysis
- Static code analysis
- Dependency scanning
- Security vulnerability detection
- Style and quality checks
- Custom security rules
3. Tool Integration
- Bandit (security scanner)
- Flake8 (style checker)
- MyPy (type checker)
- Pylint (code analysis)
- Custom security tools
Security Policies
Three levels of execution policies:
ALLOW: Code passes all security checksALLOW_WITH_MONITORING: Code requires runtime monitoringBLOCKED: Code contains security violations
Allowed Libraries
The system maintains a whitelist of common data science and analysis libraries:
- pandas, numpy, scipy
- sklearn, tensorflow, torch
- matplotlib, seaborn
- nltk, spacy, transformers
- Standard Python libraries
Configuration
Security rules can be configured through the SecurityConfig class:
from security import SecurityConfig
config = SecurityConfig()
config.BLOCKED_IMPORTS.add('dangerous_module')
config.DANGEROUS_FUNCTIONS.add('risky_function')
Response Format
@dataclass
class CodeValidationResponse:
result: ValidationResult
message: str
details: Optional[List[str]]
line_numbers: Optional[List[int]]
execution_policy: Optional[ExecutionPolicy]
Best Practices
- Always run in fast mode first for quick validation
- Use parallel tool execution for larger codebases
- Configure security rules based on your environment
- Monitor and log validation results
- Update security rules regularly
Limitations
- Cannot catch all runtime security issues
- Some false positives in security detection
- Limited to Python code analysis
- Requires external tool installation
- May miss sophisticated attack vectors
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
License
MIT License - See LICENSE file for details
Support
For issues and feature requests, please create an issue in the repository.
Metadata
Release files for PuriPy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| puripy-0.1.0.tar.gz | 16.2 kB | Without provenance | Details for puripy-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| PuriPy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for PuriPy-0.1.0-py3-none-any.whl |
Total release size: 32.8 kB
Release files / puripy-0.1.0.tar.gz
| Download URL | puripy-0.1.0.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10bf58a32cd2181fae542750907d5a399f18b207cca794c5b0d4068850c66e49
|
|
BLAKE2b-256 checksum How to use checksums |
38efc99e17779897a4ebdb277dc039a5231227f8020ae387815dac92bdd21762
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / PuriPy-0.1.0-py3-none-any.whl
| Download URL | PuriPy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78d86bd2fe664946f62b281f3c285719824d70fe77f276fc74f7bdb3b8b62595
|
|
BLAKE2b-256 checksum How to use checksums |
4191ac20f9693f37baedf05930dd9732ecf400641b29ff7c76d517fba4b32bfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for PuriPy 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.