Skip to main content
# 🔒 gbkomi-filter

A lightweight yet powerful Python library for **sanitizing, validating, and blocking malicious inputs** in your applications.

---

## ✨ Features

- 🛡️ Protects against **SQL Injection, Command Injection, XSS, Prompt Injection, and Path Traversal**
- 🧹 Automatic Unicode normalization and control character removal
- 🕵️ Detects obfuscated payloads (Base64, Hex encoding, high-entropy strings)
- ⚙️ Three operation modes: `block` (default), `log` (record only), `transparent` (sanitize and pass)
- 📋 Built-in threat logging for post-mortem analysis
- 🚀 Zero external dependencies (pure Python)
- ✅ Type validation (email, URL, integer)

---

## 📦 Installation

### From PyPI (coming soon)
```bash
pip install gbkomi-filter

From source (development)

git clone https://github.com/yourusername/gbkomi-filter.git
cd gbkomi-filter
pip install -e .

🚀 Quick Start

from gbkomi_filter import FilterEngine, SecurityException

# Initialize the engine
engine = FilterEngine(mode='block')  # 'block' | 'log' | 'transparent'

# Example 1: Safe input
try:
    result = engine.filter("Hello World")
    print(f"✅ Allowed: {result}")
except SecurityException as e:
    print(f"❌ Blocked: {e}")

# Example 2: Malicious input (SQL Injection)
try:
    result = engine.filter("' ; DROP TABLE users; --")
    print(f"✅ Allowed: {result}")
except SecurityException as e:
    print(f"❌ Blocked: {e}")
    # Output: Blocked: Threat detected: sql

# Example 3: Type validation (email)
try:
    result = engine.filter("user@example.com", expected_type='email')
    print(f"✅ Valid email: {result}")
except SecurityException as e:
    print(f"❌ Invalid: {e}")

# Example 4: Log mode (monitor without blocking)
log_engine = FilterEngine(mode='log')
result = log_engine.filter("'; DROP TABLE users; --")
print(f"Result: {result}")  # Passes through
print(f"Logs: {log_engine.get_logs()}")

⚙️ Configuration

FilterEngine(mode, allowlist)

Parameter Type Default Description
mode str 'block' Operation mode: 'block', 'log', or 'transparent'
allowlist list [] List of exact-match inputs that bypass all filters

engine.filter(input, expected_type, schema)

Parameter Type Default Description
user_input Any Required The input to validate (auto-converted to string)
expected_type str None Enforce type: 'int', 'email', 'url', or 'string'
schema dict None JSON schema validation for structured data

🧪 Running Tests

# Install dev dependencies
pip install -r requirements-dev.txt

# Run tests
pytest tests/

# Run with coverage
pytest --cov=gbkomi_filter tests/

📂 Project Structure

gbkomi-filter/
├── src/gbkomi_filter/
│   ├── __init__.py    # Public API
│   ├── guard.py       # FilterEngine core logic
│   ├── rules.py       # All threat patterns (SQL, XSS, etc.)
│   └── utils.py       # Normalization, encoding detection, validation
├── tests/             # Unit tests
├── examples/          # Usage examples
├── README.md          # This file
├── LICENSE            # MIT License
└── pyproject.toml     # Build configuration

🛡️ Threat Detection Coverage

Attack Type Detection Pattern Examples
SQL Injection ' OR '1'='1, DROP TABLE, UNION SELECT
Command Injection ;, `
XSS <script>, onerror=, javascript:
Code Injection __import__, eval, exec, os.system
Path Traversal ../, /etc/passwd, C:\Windows\
Prompt Injection ignore previous instructions, act as

📄 License

This project is licensed under the MIT License – see the LICENSE file for details.


🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing)
  5. Open a Pull Request

Made with ❤️ for the security community.

Metadata

Release files for gbkomi-filter 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gbkomi-filter 1.0.0
File Size Uploaded Provenance
gbkomi_filter-1.0.0.tar.gz 16.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gbkomi-filter 1.0.0
File Interpreter ABI Platform
gbkomi_filter-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.8 kB

Release files / gbkomi_filter-1.0.0.tar.gz

Download URL gbkomi_filter-1.0.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
914dc8e5ebcad1614482a4297eef6e2bf4cb4a861b355056c0b349700715e114
BLAKE2b-256 checksum
How to use checksums
ed6b1e14245bca8b7add6dff1a599d00272b129082b0f1a79199285e10c2d628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / gbkomi_filter-1.0.0-py3-none-any.whl

Download URL gbkomi_filter-1.0.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53964eb9cbc2fc0b4911df16726160c1f58669278543e5c601ff826f6902cce1
BLAKE2b-256 checksum
How to use checksums
d318b540931c78a713f1cb7c75b9a3b1246d3e09586c6ed34cd25f5d45c639df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for gbkomi-filter 1.0.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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page