Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
86ebb07
Add security vulnerability management features including a vulnerabil…
Suyashd999 Jan 1, 2026
d1d0afb
Add thread-safe apt package list update mechanism in AutonomousPatche…
Suyashd999 Jan 1, 2026
00a5fa2
Refactor argument parser in security_scheduler.py to streamline comma…
Suyashd999 Jan 1, 2026
0df209e
Fix f-string without placeholder causing pipeline failure.
Suyashd999 Jan 1, 2026
c38db9d
Add root privilege check before installing systemd timer in security_…
Suyashd999 Jan 1, 2026
2f99186
Refactor logging statements in autonomous_patcher.py, cli.py, and sec…
Suyashd999 Jan 1, 2026
24319cb
Enhance vulnerability scanning logic in vulnerability_scanner.py to a…
Suyashd999 Jan 1, 2026
b7cfe68
Update SECURITY_MANAGEMENT.md to correct command option from --enable…
Suyashd999 Jan 1, 2026
69cf81e
Add unit tests for Autonomous Patcher, Security Scheduler, and Vulner…
Suyashd999 Jan 2, 2026
da2f56e
Enhance vulnerability scanning in vulnerability_scanner.py
Suyashd999 Jan 2, 2026
2a22cf4
Add version comparison and vulnerability fix verification in Autonomo…
Suyashd999 Jan 2, 2026
24b9299
Enhance Autonomous Patcher configuration management
Suyashd999 Jan 2, 2026
0610d0e
Remove unused imports in test_autonomous_patcher.py to improve code c…
Suyashd999 Jan 2, 2026
60196fb
Refactor whitespace in ensure_apt_updated method for improved readabi…
Suyashd999 Jan 2, 2026
5529c04
Refactor whitespace in docstrings for improved readability in autonom…
Suyashd999 Jan 2, 2026
df9adcd
Add allow_unverified_patches option to Autonomous Patcher
Suyashd999 Jan 2, 2026
baf9cdc
Refactor whitespace in security_scheduler.py and vulnerability_scanne…
Suyashd999 Jan 2, 2026
92cb92e
Refactor whitespace for improved readability across multiple files
Suyashd999 Jan 2, 2026
2b8afcb
Enhance vulnerability scanner with package name and version validation
Suyashd999 Jan 2, 2026
2e1a560
Update dry run logic in CortexCLI for clarity
Suyashd999 Jan 2, 2026
37c68fa
Refactor next_run assignment in SecurityScheduler for clarity
Suyashd999 Jan 2, 2026
cb79102
Enhance Autonomous Patcher with progress indicators and improved logging
Suyashd999 Jan 2, 2026
6c9ecc0
Merge branch 'main' into security-422
Anshgrover23 Jan 7, 2026
83958f8
Refactor apt update handling in Autonomous Patcher for instance-level…
Suyashd999 Jan 8, 2026
9283a94
Refactor Cortex CLI and Security Scheduler for improved clarity and f…
Suyashd999 Jan 8, 2026
bfdef1c
Merge branch 'main' into security-422
Suyashd999 Jan 8, 2026
9c493ee
Refactor patching logic in SecurityScheduler for improved readability
Suyashd999 Jan 8, 2026
8328205
Enhance schedule creation in Cortex CLI with dry-run option
Suyashd999 Jan 8, 2026
3f2eae6
Enhance vulnerability caching in VulnerabilityScanner
Suyashd999 Jan 8, 2026
90dd862
Refactor Autonomous Patcher and Vulnerability Scanner for enhanced co…
Suyashd999 Jan 8, 2026
6424313
Implement custom frequency handling in SecurityScheduler and enhance …
Suyashd999 Jan 8, 2026
29b3238
Refactor package version retrieval in Cortex CLI and VulnerabilitySca…
Suyashd999 Jan 8, 2026
d41aad2
Add root privilege checks in Autonomous Patcher
Suyashd999 Jan 9, 2026
7f2298b
Merge branch 'main' into security-422
Anshgrover23 Jan 9, 2026
60099f8
Merge branch 'main' into security-422
Anshgrover23 Jan 11, 2026
d5831bc
Refactor candidate version parsing in Autonomous Patcher
Suyashd999 Jan 12, 2026
7f729f6
Merge branch 'main' into security-422
Anshgrover23 Jan 12, 2026
442cf67
Merge branch 'main' into security-422
Anshgrover23 Jan 13, 2026
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
791 changes: 791 additions & 0 deletions cortex/autonomous_patcher.py

Large diffs are not rendered by default.

340 changes: 340 additions & 0 deletions cortex/cli.py

Large diffs are not rendered by default.

537 changes: 537 additions & 0 deletions cortex/security_scheduler.py

Large diffs are not rendered by default.

885 changes: 885 additions & 0 deletions cortex/vulnerability_scanner.py

Large diffs are not rendered by default.

261 changes: 261 additions & 0 deletions docs/SECURITY_MANAGEMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
# Security Vulnerability Management & Autonomous Patching

## Problem

**Security vulnerabilities in dependencies are the #1 attack vector for Linux systems.** According to recent CVE data:

- **25,000+ new CVEs** are published annually
- **60% of breaches** exploit known, unpatched vulnerabilities
- Average time from CVE publication to exploit: **15 days**
- Average enterprise patching cycle: **102 days**
Comment on lines +5 to +10
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation references statistics like "Average enterprise patching cycle: 102 days" and "60% of breaches" but doesn't provide citations or sources for these claims. For credibility and to allow readers to verify these statistics, consider adding references to industry reports or research studies that support these numbers.

Copilot uses AI. Check for mistakes.

Cortex Linux currently has **zero automated security monitoring**. Users must:

1. Manually check each of their 2,000+ installed packages
2. Cross-reference against CVE databases (NVD, OSV, etc.)
3. Determine which updates fix which vulnerabilities
4. Hope they don't miss a critical exploit

**This is unacceptable for an AI-native package manager.**

### Real-World Impact

| Vulnerability | Impact |
|---------------|--------|
| **Log4Shell (CVE-2021-44228)** | Organizations without automated scanning took weeks to identify affected systems |
| **Heartbleed (CVE-2014-0160)** | OpenSSL vulnerability affected 17% of "secure" web servers |
| **Monthly kernel patches** | Linux releases security updates monthly — missing one can expose the entire system |

### Current State

```bash
# Today: Manual, error-prone, incomplete
$ apt list --upgradable | grep security # Doesn't show CVE severity
$ apt-cache policy openssl # No vulnerability context
```

Users are flying blind.

---

## Proposed Solution

Implement **continuous vulnerability scanning** with **autonomous patching** capabilities.

### Core Features

| Feature | Description |
|---------|-------------|
| **Vulnerability Scanner** | Continuously monitor installed packages against CVE databases |
| **Autonomous Patcher** | Automatically patch vulnerabilities with safety controls |
| **Security Scheduler** | Monthly/weekly/daily automated security maintenance |
| **Rollback Support** | All patches tracked in history, fully reversible |

### Example Commands

```bash
# Scan all installed packages for vulnerabilities
cortex security scan --all

# Output:
# 🔍 Scanning: 2636/2636 (100%) | Vulnerabilities found: 47
#
# 📊 Scan Results:
# 🔴 Critical: 3
# 🟠 High: 12
# 🟡 Medium: 24
# 🟢 Low: 8

# Scan specific package
cortex security scan --package openssl

# Show only critical vulnerabilities
cortex security scan --critical

# Autonomous patching (dry-run by default for safety)
cortex security patch --scan-and-patch --strategy critical_only

# Actually apply patches
cortex security patch --scan-and-patch --strategy critical_only --apply

# Set up monthly automated patching (suitable for desktops/low-risk systems)
cortex security schedule create monthly-patch --frequency monthly --enable-patch

# For servers/critical systems, use weekly with critical-only strategy
cortex security schedule create weekly-critical --frequency weekly --enable-patch
Comment on lines +82 to +85
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch strategy names use snake_case ('critical_only', 'high_and_above') but the comparison text in documentation uses spaces. Consider using consistent terminology throughout. For example, the enum values should match how they're described in user-facing documentation.

Suggested change
cortex security schedule create monthly-patch --frequency monthly --enable-patch
# For servers/critical systems, use weekly with critical-only strategy
cortex security schedule create weekly-critical --frequency weekly --enable-patch
cortex security schedule create monthly-patch --frequency monthly --strategy high_and_above --enable-patch
# For servers/critical systems, use weekly with critical_only strategy
cortex security schedule create weekly-critical --frequency weekly --strategy critical_only --enable-patch

Copilot uses AI. Check for mistakes.
cortex security schedule install-timer monthly-patch
Comment on lines +85 to +86
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The '--patch_strategy' option in the command example has an inconsistent naming pattern. Looking at the code, it should use hyphens like '--patch-strategy' to match the argparse configuration in the CLI, not underscores.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command example on line 86 is missing the '--apply' flag mentioned in the description on line 79. The example should include '--apply' to show how to actually apply patches in non-dry-run mode.

Suggested change
cortex security schedule install-timer monthly-patch
cortex security schedule install-timer monthly-patch --apply

Copilot uses AI. Check for mistakes.
```

### Patching Frequency Guidelines

Different systems have different security requirements. Choose the appropriate patching frequency based on your use case:

| System Type | Recommended Frequency | Rationale |
|-------------|----------------------|-----------|
| **Production servers** | Weekly or daily (critical only) | Minimize exposure window for exploitable vulnerabilities |
| **Internet-facing services** | Daily (critical/high) | High risk of exploitation; CVEs are weaponized within ~15 days |
| **Development workstations** | Weekly | Balance productivity with security; less exposure than servers |
| **Desktop/personal use** | Monthly | Standard Linux practice; lower risk profile |
| **Air-gapped/isolated systems** | Monthly | Limited attack surface; coordinate with maintenance windows |
| **Compliance-regulated (SOC2, HIPAA)** | Per policy, typically weekly | Meet audit requirements; document all patching activity |

**When to patch more frequently:**
- After major CVE disclosures (e.g., Log4Shell, Heartbleed-class vulnerabilities)
- Systems handling sensitive data (PII, financial, healthcare)
- Publicly accessible services (web servers, APIs, databases)

**When monthly is appropriate:**
- Internal-only systems with limited network exposure
- Systems where stability is prioritized over immediate patching
- Environments with change control processes requiring scheduled maintenance windows

### Safety Controls

| Control | Description |
|---------|-------------|
| **Dry-run default** | Shows what would be patched without making changes |
| **Whitelist/Blacklist** | Control which packages can be auto-patched |
| **Severity filtering** | Only patch above threshold (e.g., critical only) |
| **Rollback support** | All patches recorded in history, reversible |
| **Systemd integration** | Native Linux scheduling via timers |

### Data Sources

| Source | Purpose | Speed |
|--------|---------|-------|
| **OSV (Open Source Vulnerabilities)** | Primary database, comprehensive | Fast |
| **NVD (National Vulnerability Database)** | Fallback for critical packages | Slower |
| **24-hour caching** | Reduces API load | Instant (cached) |

---

## Why This Matters

### For Cortex Linux

1. **Differentiation**: No other package manager offers AI-assisted security scanning + natural language patching
2. **Enterprise requirement**: Automated compliance for SOC2, ISO27001, HIPAA
3. **User safety**: Protect users from the 25,000+ CVEs published each year
4. **Flexible patching schedules**: From daily (critical systems) to monthly (desktops) — we make it effortless

### Industry Statistics

```text
┌─────────────────────────────────────────────────────────────┐
│ THE PATCHING GAP │
├─────────────────────────────────────────────────────────────┤
│ │
│ CVE Published ──────────────────────────────────────────▶ │
│ │ │
│ │ 15 days ┌─────────────────┐ │
│ ├───────────▶│ Exploit Created │ │
│ │ └─────────────────┘ │
│ │ │
│ │ 102 days ┌─────────────────┐ │
│ └───────────▶│ Enterprise Patch│ ← TOO SLOW! │
│ └─────────────────┘ │
│ │
│ WITH CORTEX: │
│ │ < 24 hrs ┌─────────────────┐ │
│ └───────────▶│ Auto-Detected │ ← FIXED │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
```

---

## Acceptance Criteria

- [ ] `cortex security scan --all` scans installed packages against CVE databases
- [ ] `cortex security scan --package <name>` scans specific package
- [ ] `cortex security scan --critical` shows only critical vulnerabilities
- [ ] `cortex security patch --scan-and-patch` creates patch plan (dry-run)
- [ ] `cortex security patch --scan-and-patch --apply` applies patches
- [ ] `cortex security schedule create` creates automated schedules
- [ ] `cortex security schedule list` lists all schedules
- [ ] `cortex security schedule run <id>` manually runs a schedule
- [ ] `cortex security schedule install-timer` installs systemd timer
- [ ] All patches recorded in installation history with rollback support
- [ ] Configurable whitelist/blacklist for packages
- [ ] Severity filtering (critical_only, high_and_above, automatic)
- [ ] Progress output during long scans
- [ ] Caching to avoid repeated API calls
Comment on lines +170 to +183
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The acceptance criteria list includes items that should be checked off or removed before merging. All items are marked as unchecked (- [ ]) which suggests this is still a work in progress, or the checkboxes should be updated to reflect completed items.

Suggested change
- [ ] `cortex security scan --all` scans installed packages against CVE databases
- [ ] `cortex security scan --package <name>` scans specific package
- [ ] `cortex security scan --critical` shows only critical vulnerabilities
- [ ] `cortex security patch --scan-and-patch` creates patch plan (dry-run)
- [ ] `cortex security patch --scan-and-patch --apply` applies patches
- [ ] `cortex security schedule create` creates automated schedules
- [ ] `cortex security schedule list` lists all schedules
- [ ] `cortex security schedule run <id>` manually runs a schedule
- [ ] `cortex security schedule install-timer` installs systemd timer
- [ ] All patches recorded in installation history with rollback support
- [ ] Configurable whitelist/blacklist for packages
- [ ] Severity filtering (critical_only, high_and_above, automatic)
- [ ] Progress output during long scans
- [ ] Caching to avoid repeated API calls
- `cortex security scan --all` scans installed packages against CVE databases
- `cortex security scan --package <name>` scans specific package
- `cortex security scan --critical` shows only critical vulnerabilities
- `cortex security patch --scan-and-patch` creates patch plan (dry-run)
- `cortex security patch --scan-and-patch --apply` applies patches
- `cortex security schedule create` creates automated schedules
- `cortex security schedule list` lists all schedules
- `cortex security schedule run <id>` manually runs a schedule
- `cortex security schedule install-timer` installs systemd timer
- All patches recorded in installation history with rollback support
- Configurable whitelist/blacklist for packages
- Severity filtering (critical_only, high_and_above, automatic)
- Progress output during long scans
- Caching to avoid repeated API calls

Copilot uses AI. Check for mistakes.

---

## Technical Implementation

### Architecture

```
┌─────────────────────────────────────────────────────────────────┐
│ CORTEX SECURITY │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ ┌───────────┐ │
│ │ Vulnerability │───▶│ Autonomous │───▶│ Security │ │
│ │ Scanner │ │ Patcher │ │ Scheduler │ │
│ └────────┬─────────┘ └────────┬─────────┘ └─────┬─────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Installation History │ │
│ │ (Rollback Support) │ │
│ └──────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
┌───────────────────────────────┐
│ External CVE Databases │
│ • OSV (Open Source Vulns) │
│ • NVD (National Vuln DB) │
└───────────────────────────────┘
```

### Files

| File | Purpose |
|------|---------|
| `cortex/vulnerability_scanner.py` | Scans packages against CVE databases |
| `cortex/autonomous_patcher.py` | Applies patches with safety controls |
| `cortex/security_scheduler.py` | Manages scheduled scans/patches |
| `cortex/cli.py` | CLI integration (`cortex security ...`) |

### Configuration

Settings stored in `~/.cortex/patcher_config.json`:

```json
{
"whitelist": ["nginx", "openssl"],
"blacklist": ["linux-image-generic"],
"min_severity": "medium"
}
```

---

## Priority

**🔴 Critical**

## Labels

`security`, `feature`, `high-priority`, `enterprise`

## Estimated Effort

- Implementation: 2-3 days
- Testing: 1 day
- Documentation: 0.5 day

---

## References

- [OSV API Documentation](https://osv.dev/docs/)
- [NVD API Documentation](https://nvd.nist.gov/developers)
- [CVSS v3.1 Specification](https://www.first.org/cvss/v3.1/specification-document)
- [Linux Security Updates Best Practices](https://wiki.ubuntu.com/Security/Upgrades)

Loading
Loading