Modular library for analysis, data protection, and validation
Project description
🔐 SecurityCore
Read this in English | Читать на Русском
SecurityCore — это швейцарский нож для обеспечения безопасности ваших данных. Объединил продвинутый анализ энтропии, многоуровневую защиту от инъекций и строгую валидацию в один лаконичный SDK.
🛠 Ключевые возможности
| Модуль | Описание | Основные функции |
|---|---|---|
| 🔑 Crypto | Продвинутая криптография (Argon2, JWT) | hash_password, verify_password, create_token_pair |
| 🛡️ Protection | Защита от классических атак (IDS, nh3 XSS) | sanitize_xss, ensure_no_sql_injection, SafeString |
| ✔️ Validation | Строгая проверка типов и форматов | validate_email, validate_ip, validate_url |
| 📜 Audit | Протоколирование для SIEM | audit, audit_json |
| 🔌 Integrations | Готовые Middleware для фреймворков | SecurityAuditMiddleware (FastAPI) |
🚀 Быстрый старт
1. Установка
# Установка через pip
pip install securitycore
# Для работы с FastAPI добавьте extras
pip install securitycore[fastapi]
# Для разработки и контрибьютинга
git clone https://github.com/Mihhail327/SecurityCore.git
cd SecurityCore && poetry install
2. Примеры использования
🧠 Анализ сложности (Энтропия)
Не просто считает длину, а вычисляет реальную стойкость к брутфорсу.
from securitycore import password_analyzer
res = password_analyzer("SuperSecret123!")
print(f"📊 Стойкость: {res['strength']} ({res['bits']:.2f} bits)")
🧼 Очистка ввода (XSS/SQLi)
from securitycore import input_sanitizer
raw_html = "<img src=x onerror=alert(1)> Привет!"
clean_html = input_sanitizer(raw_html)
# Результат: <img src=x onerror=alert(1)> Привет!
🔑 Хеширование паролей (Argon2)
from securitycore import hash_password, verify_password
# Автоматически использует надежные настройки памяти и времени
pwhash = hash_password("SuperSecret123!")
is_valid = verify_password("SuperSecret123!", pwhash)
🛡️ FastAPI Интеграция (IDS и Security Headers)
from fastapi import FastAPI
from securitycore.integrations import SecurityAuditMiddleware
app = FastAPI()
# Автоматически логирует XSS/SQLi атаки и добавляет заголовки безопасности
app.add_middleware(SecurityAuditMiddleware)
🔄 Миграция (с v1.0 на v1.1+)
В новой версии мы перешли на Argon2 и JWT.
Токены: Ранее generate_token возвращал кастомный HEX-формат. Теперь он использует индустриальный стандарт JWT (PyJWT).
Если вы используете токены, вам не нужно менять код вызова generate_token(payload, key), но учтите, что формат изменился на ey....
Хеширование: Для новых паролей используйте hash_password. Старая функция hash_data (PBKDF2) оставлена для обратной совместимости, но помечена как Legacy.
🧪 Надежность и Тестирование
Придерживаюсь подхода Test-Driven Development. Стабильность гарантирована полным покрытием pytest.
poetry run pytest -v
👨💻 Об авторе
Проект поддерживается Mihhail327.
Библиотека SecurityCore выросла из личного интереса к теме информационной безопасности и стремления создавать инструменты, которые делают код чище и защищеннее.
📜 Лицензия
Распространяется под лицензией MIT. Подробности в файле LICENSE.
🔐 SecurityCore (English Version)
SecurityCore is a Swiss Army knife for securing your data. It combines advanced entropy analysis, multi-layered injection protection, and strict validation into one concise SDK.
🛠 Key Features
| Module | Description | Core Functions |
|---|---|---|
| 🔑 Crypto | Advanced cryptography (Argon2, JWT) | hash_password, verify_password, create_token_pair |
| 🛡️ Protection | Classic attack prevention (IDS, nh3 XSS) | sanitize_xss, ensure_no_sql_injection, SafeString |
| ✔️ Validation | Strict type and format validation | validate_email, validate_ip, validate_url |
| 📜 Audit | SIEM-ready logging | audit, audit_json |
| 🔌 Integrations | Ready-to-use framework middleware | SecurityAuditMiddleware (FastAPI) |
🚀 Quick Start
1. Installation
# Install via pip
pip install securitycore
# For FastAPI integration, add the extras
pip install securitycore[fastapi]
# For development and contributing
git clone https://github.com/Mihhail327/SecurityCore.git
cd SecurityCore && poetry install
2. Usage Examples
🧠 Complexity Analysis (Entropy)
It doesn't just count the length; it calculates the real resistance against brute-force attacks.
from securitycore import password_analyzer
res = password_analyzer("SuperSecret123!")
print(f"📊 Strength: {res['strength']} ({res['bits']:.2f} bits)")
🧼 Input Sanitization (XSS/SQLi)
from securitycore import input_sanitizer
raw_html = "<img src=x onerror=alert(1)> Hello!"
clean_html = input_sanitizer(raw_html)
# Result: <img src=x onerror=alert(1)> Hello!
🔑 Password Hashing (Argon2)
from securitycore import hash_password, verify_password
# Automatically uses secure memory and time cost settings
pwhash = hash_password("SuperSecret123!")
is_valid = verify_password("SuperSecret123!", pwhash)
🛡️ FastAPI Integration (IDS & Security Headers)
from fastapi import FastAPI
from securitycore.integrations import SecurityAuditMiddleware
app = FastAPI()
# Automatically logs XSS/SQLi attacks and adds security headers
app.add_middleware(SecurityAuditMiddleware)
🔄 Migration (from v1.0 to v1.1+)
In the new version, we migrated to Argon2 and JWT.
Tokens: Previously, generate_token returned a custom HEX format. Now it uses the industry standard JWT (PyJWT). If you use tokens, you don't need to change the generate_token(payload, key) call code, but be aware that the format has changed to ey....
Hashing: For new passwords, use hash_password. The old hash_data (PBKDF2) function is kept for backward compatibility but marked as Legacy.
🧪 Reliability and Testing
I follow the Test-Driven Development approach. Stability is guaranteed by full pytest coverage.
poetry run pytest -v
👨💻 About the Author
The project is maintained by Mihhail327.
The SecurityCore library grew out of a personal interest in information security and a desire to create tools that make code cleaner and more secure.
📜 License
Distributed under the MIT license. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 securitycore-1.2.2.tar.gz.
File metadata
- Download URL: securitycore-1.2.2.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.13.13 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ab4fed181b0a38e1d39646b8f9ceaf099f3e20cbc01368a357fd54c3112f8f1
|
|
| MD5 |
d56dd364a38c938ecd89caf36aaf9ab8
|
|
| BLAKE2b-256 |
b52173e125bb200332235a089a7e04d089b0ec7af41ce2a620fa9e2afc97011a
|
File details
Details for the file securitycore-1.2.2-py3-none-any.whl.
File metadata
- Download URL: securitycore-1.2.2-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.13.13 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff76da448f5f7e95ee4c32f2079b24cfcacc57ea6183cc71b0c27c3cd04ebfd6
|
|
| MD5 |
a00033a39074ab4fad9dd58678048a13
|
|
| BLAKE2b-256 |
a30c2f28b71f891afc4522773893c419eac9d1dd27dc2cc45179287c6ca7b948
|