Metadata-Version: 2.4
Name: vcd-python
Version: 0.1.0
Summary: Volatile Cyber Defense: A self-destructing security middleware for Python web applications
Project-URL: Homepage, https://github.com/nanikore7250/vcd-python
Project-URL: Paper, https://zenodo.org/records/19648507
Project-URL: Bug Tracker, https://github.com/nanikore7250/vcd-python/issues
License: MIT License
        
        Copyright (c) 2026 nanikore7250
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: intrusion-detection,middleware,security,volatile-cyber-defense
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.8
Provides-Extra: dev
Requires-Dist: flask; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Provides-Extra: flask
Requires-Dist: flask>=2.0; extra == 'flask'
Description-Content-Type: text/markdown

# vcd-python

**Volatile Cyber Defense (VCD)** の Python 実装です。攻撃を検知したらプロセスが即座に証拠を保全して自壊し、クリーンな状態で回復するセキュリティミドルウェアです。

論文: [DOI: 10.5281/zenodo.19648507](https://zenodo.org/records/19648507)

## インストール

```bash
pip install vcd-python
```

Flask と使用する場合:

```bash
pip install vcd-python[flask]
```

## クイックスタート

```python
from flask import Flask
from vcd import VCDMiddleware

app = Flask(__name__)

@app.route("/")
def index():
    return "Hello, World!"

# デフォルト：検知 → 証拠保全のみ（自壊・ブロックなし）
app.wsgi_app = VCDMiddleware(app.wsgi_app)
```

自壊を有効化する場合（本番推奨）:

```python
app.wsgi_app = VCDMiddleware(
    app.wsgi_app,
    self_destruct=True,
    forensics_path="/var/vcd/forensics.jsonl",
)
```

## ⚠️ 警告

`self_destruct=True` を設定すると、攻撃検知時にプロセスが `os._exit(1)` で即時終了します。
**supervisord・systemd・Kubernetes 等の自動再起動機構が必須です。**

詳細は [SECURITY.md](SECURITY.md) を参照してください。

## VCD の動作フロー

このプロダクトのコアは **証拠保全** と **自壊** です。

```
攻撃リクエスト
  ↓
検知（XSS・SQLi 等）
  ↓
証拠書き出し（forensics.jsonl へ）  ← コア
  ↓
自壊（os._exit(1)）                 ← コア
  ↓
supervisord 等による自動再起動
```

## IP ブロック機能（オプション）

デフォルトでは無効です。`block=True` を指定すると、攻撃元 IP を記録し、再起動後も同一 IP を 403 で遮断します。

```python
app.wsgi_app = VCDMiddleware(
    app.wsgi_app,
    self_destruct=True,
    forensics_path="/var/vcd/forensics.jsonl",
    block=True,
    blocklist_path="/var/vcd/blocklist.txt",
)
```

```
（再起動後）
  ↓
ブロックリスト読み込み → 同一 IP を 403 で遮断
```

## 設定オプション

| パラメータ | デフォルト | 説明 |
|---|---|---|
| `detectors` | `[XSSDetector(), SQLiDetector()]` | 使用する検知器のリスト |
| `self_destruct` | `False` | 自壊の有効化 |
| `forensics_path` | `/var/vcd/forensics.jsonl` | 証拠ファイルのパス |
| `block` | `False` | IP ブロック機能の有効化 |
| `blocklist_path` | `/var/vcd/blocklist.txt` | ブロックリストのパス（`block=True` 時に使用） |
| `on_detect` | `None` | 検知時のコールバック関数 |

## カスタム検知器

```python
from vcd import VCDMiddleware
from vcd.detector import BaseDetector

class MyDetector(BaseDetector):
    def detect(self, request):
        if "malicious" in request.get_data(as_text=True):
            return True, "custom pattern detected"
        return False, ""

app.wsgi_app = VCDMiddleware(
    app.wsgi_app,
    detectors=[MyDetector()],
    self_destruct=True,
)
```

## ライセンス

MIT License — 詳細は [LICENSE](LICENSE) を参照してください。
