**sqlhund** detects SQL injection patterns with CWE and CAPEC classification.Written in Rust with Python bindings via [PyO3](https://pyo3.rs/), it provides security analysis for AI agents that generate or relay SQL queries, preventing database manipulation through dual-axis threat intelligence (technique vs impact).
Project description
sqlhund
Rust-powered auditable SQL injection detection for Python 🐍. Built for AI agents ✨.
sqlhund detects SQL injection patterns with CWE and CAPEC classification. Written in Rust with Python bindings via PyO3, it provides security analysis for AI agents that generate or relay SQL queries, preventing database manipulation through dual-axis threat intelligence (technique vs impact).
>>> import sqlhund
>>> sqlhund.is_query_malicious("SELECT * FROM users WHERE id = 1")
False
>>> sqlhund.is_query_malicious("' OR 1=1 --")
True
[!NOTE]
The primary goal is to prevent AI agents from manipulating data in or the structure of your database.
Installation
pip install sqlhund # pip
poetry add sqlhund # poetry
uv add sqlhund # uv
Requires Python 3.10+. No runtime dependencies.
Quick Start
sqlhund exposes two functions — that's the entire API:
import sqlhund
# Simple boolean check
sqlhund.is_query_malicious("SELECT * FROM users; DROP TABLE users")
# True
# Detailed analysis with security classification
result = sqlhund.analyze_query("SELECT * FROM users; DROP TABLE users")
# {
# 'is_malicious': True,
# 'matches': {
# 'general': [
# {
# 'technique': ['CWE-89'], # HOW: SQL Injection
# 'impact': ['CWE-285', 'CWE-471'], # WHAT: Auth bypass + data tampering
# 'capec': [66] # CAPEC-66: SQL Injection
# }
# ]
# }
# }
# File operation attacks detected
result = sqlhund.analyze_query("SELECT load_extension('evil')")
# {
# 'is_malicious': True,
# 'matches': {
# 'sqlite': [
# {
# 'technique': ['CWE-89', 'CWE-610', 'CWE-114'],
# 'impact': ['CWE-200', 'CWE-285'],
# 'capec': [470]
# }
# ]
# }
# }
# Safe queries pass through cleanly
sqlhund.analyze_query("SELECT id FROM users WHERE id = 1")
# {'is_malicious': False, 'matches': {}}
Usage Examples
Validating AI-Generated SQL
import sqlhund
def execute_ai_query(query: str):
"""Execute AI-generated SQL with injection protection."""
if sqlhund.is_query_malicious(query):
raise ValueError("Potential SQL injection detected")
# Safe to execute
return database.execute(query)
Detailed Threat Analysis
result = sqlhund.analyze_query("SELECT * FROM users WHERE id = 1 OR 1=1")
if result['is_malicious']:
for db_name, patterns in result['matches'].items():
print(f"Database: {db_name}")
for pattern in patterns:
print(f" Technique: {pattern['technique']}") # CWE-89
print(f" Impact: {pattern['impact']}") # CWE-285
print(f" CAPEC: {pattern['capec']}") # 66
Pre-screening an User Input
def sanitize_search_query(user_input: str) -> str:
"""Validate search input before building SQL."""
test_query = f"SELECT * FROM products WHERE name LIKE '%{user_input}%'"
if sqlhund.is_query_malicious(test_query):
raise ValueError("Invalid search term")
return user_input
Features
- Fast: Core detection engine written in Rust, compiled to a native Python extension
- Accurate: 100% precision and recall on a 10M+ query benchmark (zero false positives, zero false negatives)
- Multi-database: Detects injection patterns targeting SQLite, PostgreSQL, and DuckDB
- Zero dependencies: Ships as a self-contained native wheel
- AI-agent ready: Designed as a guardrail for LLM-generated SQL
- Security classification: Maps detected patterns to CWE and CAPEC taxonomies for threat intelligence
Security Classification
sqlhund classifies detected patterns using industry-standard security frameworks:
Dual-Axis CWE Analysis
Analyze each detected pattern across two independent axes:
-
Technique (HOW): CWE identifiers describing the injection mechanism
- CWE-89: SQL Injection
- CWE-610: External Resource Reference (file operations)
- CWE-94/95: Code/Eval Injection
- CWE-77/78: Command/OS Command Injection
- CWE-114: Process Control (loading untrusted libraries)
- CWE-116/184: Encoding evasion and filter bypass
-
Impact (WHAT): CWE identifiers describing the attack consequences
- CWE-200: Information Disclosure
- CWE-285: Authorization Bypass
- CWE-269: Privilege Escalation
- CWE-471: Data Tampering
- CWE-400: Resource Exhaustion (DoS)
- CWE-208: Timing Side-Channel (blind injection)
- CWE-497: System Information Exposure
CAPEC Attack Patterns
Matches are also mapped to CAPEC attack pattern IDs:
- CAPEC-66: SQL Injection
- CAPEC-7: Blind SQL Injection
- CAPEC-54: Query System for Information
- CAPEC-470: Expanding Control over the OS from the Database
- CAPEC-664: Server-Side Request Forgery
OWASP Alignment
sqlhund detects patterns from OWASP Top 10 A03:2021 - Injection, covering:
- SQL Injection (CWE-89)
- Command Injection (CWE-77, CWE-78)
- Code Injection (CWE-94, CWE-95)
- File/Resource Injection (CWE-610)
Resources:
- OWASP SQL Injection Prevention Cheat Sheet
- OWASP Query Parameterization Cheat Sheet
- OWASP Injection Prevention Cheat Sheet
- CWE-89: SQL Injection
- CAPEC-66: SQL Injection
Supported Databases
sqlhund detects database-specific injection patterns for:
| Database | Detection Patterns |
|---|---|
| General | ✓ UNION, comments, tautologies, subqueries, time delays |
| SQLite | ✓ load_extension, ATTACH, PRAGMA, virtual tables |
| PostgreSQL | ✓ pg_read_file, COPY, DO blocks, dblink, extensions |
| DuckDB | ✓ read_csv, ATTACH, httpfs, CREATE SECRET, macros |
Benchmarks
Evaluated against the RbSQLi dataset — 10,304,026 labeled SQL queries (2,813,146 malicious, 7,490,880 benign).
| Predicted Malicious | Predicted Benign | |
|---|---|---|
| Actual Malicious | 2,813,146 | 0 |
| Actual Benign | 0 | 7,490,880 |
Precision: 100% · Recall: 100% · Accuracy: 100%
Building from Source
Requires Rust, Maturin, and uv.
git clone https://github.com/KanishkNavale/sqlhund
cd sqlhund
make dev # set up development environment
make build # compile debug build
make release # compile optimized release build
Testing
Run unit tests (Rust + Python):
make unittest
Run evaluation against the full RbSQLi dataset (download the dataset, place it at tests/data/wild.csv):
make wildtest
Contributing
Contributions are welcome. See the open issues or submit a pull request.
License
The MIT License licenses this project.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 sqlhund-0.0.9-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 659.4 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
370ae91f29e4da42ad5d03f5ee41a7e3c4b90cc08f79e307f666f53e4eb83b16
|
|
| MD5 |
fbae98d4c294d82a75cb203459d06d55
|
|
| BLAKE2b-256 |
b50153a1b233f28980386d438738eff8646a9370251a88779d17d416c6c6b67d
|
File details
Details for the file sqlhund-0.0.9-cp314-cp314-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp314-cp314-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 746.4 kB
- Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef8fb0a638cf32bcb58143b4157cfa78a9bf7c44b9f59d96f42bbebc6578d1dd
|
|
| MD5 |
db091c1c389b88322cae8bd7c1b49795
|
|
| BLAKE2b-256 |
1c8553b81b78441035720e5b715fce5be9bce506149741ba46ff55407ec4f867
|
File details
Details for the file sqlhund-0.0.9-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 651.3 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7bccbd62b1656495c578ede62562fb9cef6d2c2f361adbebfb9f2a3753af514
|
|
| MD5 |
dcaf0c8e656c85b997c311c35262c352
|
|
| BLAKE2b-256 |
1615c8a4593ebcee2a91ee76e29c5e564ca54fa7b4296f8a5958b3064df04463
|
File details
Details for the file sqlhund-0.0.9-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 659.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f648a9455bba597a71dda1313280d5d8317038dcdca5630e3f926277a345c2b
|
|
| MD5 |
646d6ab1211fb382b2061045fa911cb6
|
|
| BLAKE2b-256 |
c5c44ccdf53e732819fcd5d65a9f3b0843bdc6798641f39212303a05c5003d62
|
File details
Details for the file sqlhund-0.0.9-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 746.6 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8db9f15ac97d31e957fd227408a66d15fabed59037b0411fe7e6948e1313943c
|
|
| MD5 |
ee4913cde109b5cd1cf431c4d8af8eac
|
|
| BLAKE2b-256 |
b43c52cecac6dd54aea191f3ba54319ea8b31eff2b7b50c1899abf1e89a70e48
|
File details
Details for the file sqlhund-0.0.9-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 651.5 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb2849883b216e2bbb878aab6d69eb0d214feb317a60bb7a5fc456d186e8e8a0
|
|
| MD5 |
caf42c48b881598eb8499058148474f9
|
|
| BLAKE2b-256 |
fdfcc3077224cdc2a53df4bee8e9e735934475b54a71d8598f2ee636ee4ab304
|
File details
Details for the file sqlhund-0.0.9-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 659.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
730c478bb8f715a59157da84e32373fb4a97554e31176eb7c10e3cea57c0e3f5
|
|
| MD5 |
c5a72fa5da6e37c05168506f1b2fdcab
|
|
| BLAKE2b-256 |
d7534f9e6d10e0bb1c06d0a1c6da5e0bfa180edd68813df2b366ebbd2a5ad370
|
File details
Details for the file sqlhund-0.0.9-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 746.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97576fb77e12977a1144dd4a352140c9ab4d83e7db10ec20651d0b17f3eb976e
|
|
| MD5 |
a0549f6d3c26492c4827ba3611c40971
|
|
| BLAKE2b-256 |
0a19b5344e67aad8b0e1410afbc963411a986b0d243f26cd455acb572d57ed8b
|
File details
Details for the file sqlhund-0.0.9-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 651.2 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3fa5f4a60d25201a9f87e78a06b78c09054a8bfee07a9a70b138f9c753a3d62
|
|
| MD5 |
73db7495fb1f71b569d3b0bb54d21536
|
|
| BLAKE2b-256 |
7cde3b230ceae675cc6c39413daff138c4fa11b2acc7f4589a0e0b8da62830ed
|
File details
Details for the file sqlhund-0.0.9-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 660.7 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76f1d83264d600b59f73abcf4bc70eb3e15be5fc1740a2921aeef03f0db17edc
|
|
| MD5 |
5e17ee7cb7b42ed97768fbdb8ce665c6
|
|
| BLAKE2b-256 |
963cf6f13bef4935f1eae23597b846d5af75cd37d1f50e7665a13ddbeec7ce88
|
File details
Details for the file sqlhund-0.0.9-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 746.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eacc0b5ce431b0278a20fc736aaae3288dae5faab538b30034f72cec885520a
|
|
| MD5 |
a64702bfad4c873961273bbbb73dd89a
|
|
| BLAKE2b-256 |
f578d3a4cc93f0599c83f2143ff46d579539f68d18bc981f1f78101acaa505a1
|
File details
Details for the file sqlhund-0.0.9-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 651.7 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cf5e0f7c7a54fd70af87273ee78fe4a53fb234e3c6e821c5fcd52256610167a
|
|
| MD5 |
2474b34d9385da483b8db275d1d401a2
|
|
| BLAKE2b-256 |
c2c095f1f7c9f0d49f3ac403fe9d7da6dd7502a8c7ddd2339de99181e96d8919
|
File details
Details for the file sqlhund-0.0.9-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 661.2 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ffb0a46791f4d9ceebbfd534c99e839f62a93c85157c089281afc25eff309b1
|
|
| MD5 |
6088290b0857335d790a551fdc33e99b
|
|
| BLAKE2b-256 |
e479bd2727590c7ce72fde64e8c24d03e2507aff7559141c9f6f9feb0ca8b31a
|
File details
Details for the file sqlhund-0.0.9-cp310-cp310-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp310-cp310-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 746.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a63a282c63716e61410364d4711f69311094ec94e46143acdc2e19eda483524e
|
|
| MD5 |
f2458f82b0c3f701c4b54b7f19e195b8
|
|
| BLAKE2b-256 |
ccbafc3b9ca049a0cd6fdb7485bf8f053824b063b382f5e70b65ad8fc7dc4106
|
File details
Details for the file sqlhund-0.0.9-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: sqlhund-0.0.9-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 651.7 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3769f485678377bd7cab9bf436050246948ba8ea769c4c32aad5e395d7b34a
|
|
| MD5 |
ac039bc1e8b715cd4f04ba07bc68c06c
|
|
| BLAKE2b-256 |
dd0424b3f28c740e7b8ce374aba518b683494a11c1fdd74beec40a79d17f8a0d
|