Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Default ownership: the project maintainer reviews everything.
# Add collaborators as: /path/ @username (or @org/team)
* @abhinav-phi

# Notebook build system — changes here regenerate all four notebooks
/nids-backend/notebooks/colab/_build/ @abhinav-phi

# Specification set — keep docs in sync per CONTRIBUTING.md
/docs/ @abhinav-phi
79 changes: 79 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.

Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at **[GitHub — open a private contact via the repository owner's profile](https://github.com/abhinav-phi)**. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact:** Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.

**Consequence:** A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact:** A violation through a single incident or series of actions.

**Consequence:** A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.

### 3. Temporary Ban

**Community Impact:** A serious violation of community standards, including sustained inappropriate behavior.

**Consequence:** A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact:** Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.

**Consequence:** A permanent ban from any sort of public interaction within the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/inclusion).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq
100 changes: 100 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Contributing to The Sentinel NIDS

First off, thank you for considering a contribution! 🛡️

This project is a Colab-only, ML-powered Network Intrusion Detection System. The entire implementation — EDA, T4-GPU training, inference, embedded FastAPI backend, and the Gradio dashboard — lives inside **4 Colab notebooks** that are **generated** from readable Python sources. Contributions follow that build system.

---

## The Golden Rule

> **Never edit the `.ipynb` files directly.** They are build artifacts.
>
> Edit the percent-format sources in `nids-backend/notebooks/colab/_build/`, then rebuild.

```
_edit_ _build/02_Training_GPU.py → python _build/pack.py → notebooks regenerated
```

This keeps diffs reviewable, keeps the four notebooks in sync with shared fragments (`frag_*.py`), and lets CI validate everything.

---

## Development Environment

You only need local Python for **building and testing** — the notebooks themselves run on Google Colab.

| Requirement | Purpose |
|-------------|---------|
| Python 3.10+ | Running `pack.py` and `smoke_test.py` |
| `pip install "numpy<2" pandas scikit-learn shap fastapi "uvicorn[standard]" sqlalchemy requests joblib matplotlib nbformat` | Local validation toolchain |
| Google Drive | Only for actually running the notebooks (dataset + artifacts) |

> ⚠️ `numpy<2` matters locally: older `shap` builds break on NumPy 2.x. Colab resolves this automatically via its own pinned stack.

---

## Contribution Workflow

1. **Fork & branch** — `feat/<short-name>`, `fix/<short-name>`, or `docs/<short-name>`.
2. **Make your change** in `nids-backend/notebooks/colab/_build/*.py` (and `docs/` if behavior or paths changed).
3. **Rebuild the notebooks:**
```bash
cd nids-backend/notebooks/colab/_build
python pack.py # regenerates all 4 .ipynb files + nbformat/syntax validation
```
4. **Run the smoke test:**
```bash
python smoke_test.py # must print: SMOKE TEST PASSED
```
This executes notebook 03's embedded inference + API stack and asserts the full production contract (predictions, persistence, every 400/422 validation guard, severity mapping).
5. **(Notebook-logic changes)** Run the affected notebook top-to-bottom on Colab with the T4 runtime and confirm the summary tables.
6. **Open a Pull Request** using the provided template.

---

## What Changes Where

| Area | File(s) |
|------|---------|
| EDA notebook | `_build/01_EDA.py` |
| Training pipeline (models, Optuna, ROC/AUC) | `_build/02_Training_GPU.py` |
| Inference, `FlowExtractor`, FastAPI, replay | `_build/03_Inference_API.py` + `frag_*.py` |
| Gradio dashboard | `_build/04_Dashboard.py` |
| Shared inference stack | `_build/frag_inference.py` (single source of the 52-feature contract & severity map) |
| Shared API app | `_build/frag_api.py` |
| Documentation | `docs/NIDS_*.md`, `README.md`, `nids-backend/notebooks/colab/README.md` |

---

## Code Standards

- **Determinism:** every random operation uses `random_state=42` / seeded generators.
- **Artifact contract is sacred:** `model.pkl` must stay a sklearn-compatible estimator with `n_features_in_ == 52`; `scaler.pkl` stays a StandardScaler. Notebooks 03/04 depend on it.
- **No silent coercion:** malformed feature vectors are rejected (422), never "fixed" — mirror the validation semantics in `frag_api.py`.
- **Graceful GPU degradation:** CUDA cells must fall back to CPU with a clear warning, never crash.
- **No secrets:** API keys are entered via `getpass` per session. Never commit keys, tokens, or dataset files.
- **Style:** PEP 8, type hints on function signatures, docstrings for public helpers, section headers in notebook sources (`# %% [markdown]`).

---

## Commit & PR Conventions

- **Conventional commits:** `feat:`, `fix:`, `docs:`, `chore:`, `refactor:`, `test:` — e.g. `feat(colab): add per-class ROC curves to training notebook`.
- **One logical change per PR.** The repo history is split into reviewable units on purpose.
- **Docs stay in sync:** any behavior/path change gets a matching update in the relevant `docs/NIDS_*.md` and the Tracker (see `docs/NIDS_Rules.md`).

---

## Reporting Bugs & Suggesting Features

- Bugs → [Issue: Bug report](https://github.com/abhinav-phi/nids/issues/new?template=1-bug-report.md)
- Features → [Issue: Feature request](https://github.com/abhinav-phi/nids/issues/new?template=4-feature-request.md)
- Questions → [GitHub Discussions](https://github.com/abhinav-phi/nids/discussions)
- **Security vulnerabilities → [Private disclosure](https://github.com/abhinav-phi/nids/security/advisories/new) — never a public issue** (see [SECURITY.md](SECURITY.md))

---

## Licensing

By contributing, you agree that your contributions will be licensed under the [MIT License](LICENSE) that covers the project.
10 changes: 10 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Funding options for this repository.
# Uncomment a platform and add your handle to enable the "Sponsor" button.
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository

# github: [abhinav-phi]
# ko-fi: [your_kofi_username]
# patreon: [your_patreon_username]
# open_collective: [your_collective_name]
# buy_me_a_coffee: [your_bmac_username]
# custom: ["https://your-link.example"]
49 changes: 49 additions & 0 deletions .github/ISSUE_TEMPLATE/1-bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: 🐛 Bug report
about: Something in a notebook, the embedded API, or the build system is broken
title: "[Bug]: "
labels: ["bug", "triage"]
assignees: ["abhinav-phi"]
---

## Affected Component

<!-- Which notebook / part of the project is misbehaving? -->

- [ ] `01_EDA_Colab.ipynb` — EDA
- [ ] `02_Training_GPU_Colab.ipynb` — training / Optuna / evaluation
- [ ] `03_Inference_API_Colab.ipynb` — inference, FlowExtractor, FastAPI
- [ ] `04_Dashboard_Colab.ipynb` — Gradio dashboard
- [ ] `_build/` — build system (`pack.py`, `smoke_test.py`)
- [ ] `docs/` — documentation mismatch

## Environment

- **Colab runtime:** <!-- T4 GPU / CPU / other -->
- **Notebook cell number / step:** <!-- e.g. 02, Step 8.5 (Optuna) -->
- **Artifact state:** <!-- does /content/nids_artifacts/ exist? which cells ran before? -->
- **Dataset location:** <!-- MyDrive/nids_data/ or /content/ -->

## What Happened

<!-- A clear, concise description of the bug. -->

## Steps to Reproduce

1.
2.
3.

**Expected behavior:**

**Actual behavior / error output:**

```
<!-- Paste the full traceback or cell output here -->
```

## Additional Context

<!-- Screenshots, plots, or anything else that helps. -->

> ⚠️ **Security vulnerabilities are reported privately** — see [SECURITY.md](../SECURITY.md), not this template.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/4-feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: 🚀 Feature request
about: Suggest a new capability for the NIDS notebooks or pipeline
title: "[Feature]: "
labels: ["enhancement", "triage"]
assignees: ["abhinav-phi"]
---

## Problem / Motivation

<!-- What problem are you trying to solve? e.g. "The dashboard has no per-class AUC view" or "Training can't resume after a Colab disconnect". -->

## Proposed Solution

<!-- What would you like to happen? Which notebook/component should it live in? -->

- Target notebook: <!-- 01 EDA / 02 Training / 03 Inference+API / 04 Dashboard / _build -->

## Alternatives Considered

<!-- Any other approaches you've thought of, and why they're less good. -->

## Additional Context

<!-- Sketches, references (papers, datasets like NSL-KDD / UNSW-NB15), or links. -->

## Contribution

- [ ] I am willing to help implement this (see [CONTRIBUTING.md](../../.github/CONTRIBUTING.md) — edit `_build/*.py`, rebuild with `pack.py`, pass `smoke_test.py`)
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
blank_issues_enabled: false

contact_links:
- name: ❓ Question / Support
url: https://github.com/abhinav-phi/nids/discussions
about: Ask usage questions (dataset setup, artifact flow, Colab runtime) here — see also SUPPORT.md.

- name: 🔒 Security Vulnerability
url: https://github.com/abhinav-phi/nids/security/advisories/new
about: Report vulnerabilities PRIVATELY via GitHub Security Advisories — never in a public issue. See SECURITY.md.

- name: 📖 Documentation
url: https://github.com/abhinav-phi/nids/tree/main/docs
about: PRD, TechSpec, AppFlow, Design, Schema, ImplementationPlan, Tracker and Rules — most questions are answered there.
77 changes: 77 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Security Policy

**Project:** The Sentinel — Network Intrusion Detection System (NIDS)

The Sentinel is an ML-powered security tool — which means we hold it to the same standard it applies to network traffic. Thank you for taking the time to report issues responsibly.

---

## Supported Versions

| Version | Supported | Notes |
|---------|-----------|-------|
| 1.0.x (Colab Edition) | ✅ | Current release line |
| < 1.0.0 (local backend / React frontend) | ❌ | Removed in the Colab-only cleanup; fixes land on the current edition only |

---

## How to Report a Vulnerability

**Please do NOT open a public GitHub issue for security vulnerabilities.**

1. **Preferred:** use GitHub's **[Private Vulnerability Reporting](https://github.com/abhinav-phi/nids/security/advisories/new)** — this keeps the report confidential end-to-end and lets us coordinate a fix and advisory.
2. **Alternative:** open a draft security advisory through the repository's *Security* tab.

### What to include

- Affected notebook / component (`01_EDA`, `02_Training_GPU`, `03_Inference_API`, `04_Dashboard`, `_build/*`)
- A minimal reproduction (cell, payload, or request body)
- Impact assessment — what could an attacker do?
- Any known workarounds

### What to expect

| Step | Target |
|------|--------|
| Acknowledgement | within **48 hours** |
| Triage & severity assessment | within **7 days** |
| Fix or mitigation | severity-dependent, coordinated with you |
| Public disclosure | after the fix ships, credit to you unless you prefer otherwise |

---

## Scope

### ✅ In scope

- The **embedded FastAPI API** in notebook 03 (input validation, metadata handling, WebSocket fan-out, response sanitization)
- **Artifact integrity** — anything that could make `model.pkl` / `scaler.pkl` / `label_encoder.pkl` load or behave incorrectly (e.g., bypassing the `n_features_in_` parity guards)
- **Notebook code paths** that execute or persist attacker-controlled data (feature vectors, `_source_ip` metadata, replayed CSV content)
- **Supply-chain issues** in the pinned Colab dependencies (`_build` install cells)

### ❌ Out of scope

- **Google Colab platform security** — report to [Google VRP](https://bughunters.google.com) instead
- **Denial-of-service against the demo API** — the embedded server is intentionally demo-grade: optional API key (unset by default), no TLS, per-IP rate limit 120/min, WS client cap 20
- **Missing authentication / TLS on the public tunnel URLs** — documented limitation of the Colab edition; reports on this alone will be closed as *documented behavior* unless accompanied by a concrete hardening proposal
- **Attacks requiring write access to your Google Drive or Colab VM** — that is platform compromise, not a project vulnerability
- **Findings from intentionally adversarial inputs in `_build/smoke_test.py`** — those are the test suite's own fixtures

---

## Known & Accepted Limitations (by design)

These are documented in `README.md` / `docs/NIDS_PRD.md` and are **not** vulnerabilities:

1. No user authentication / authorization — the optional `X-API-Key` + WS token is defence-in-depth, not access control.
2. No TLS termination on the Cloudflare quick tunnel / Gradio share URL.
3. Per-process rate limiting and WS counters (single-process demo deployment).
4. Up to 8 of 52 missing features are zero-filled by design and surfaced via `missing_features`.

## Safe Handling

If you discover an exploitable issue, please do not run it against public deployments you do not own. For local reproduction, use the synthetic-flow fixtures in `_build/smoke_test.py` rather than live traffic.

---

*This policy follows the standard responsible-disclosure practice. For general questions (not vulnerabilities), see [SUPPORT.md](SUPPORT.md).*
Loading