-
Notifications
You must be signed in to change notification settings - Fork 4
feat(security): add vulnerability intelligence review #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43a8e2e
feat(security): add vulnerability intelligence review
elkaix ccdd84f
docs(changelog): note security intelligence review
elkaix 1948a81
fix(security): block intel client redirects
elkaix 8fc9041
fix(security-review): harden intel client, sources, CLI, and scan pip…
elkaix 4d77aec
fix(security-review): fix ruff E501/B904 and strip extras from requir…
elkaix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/pythinker-review/src/pythinker_review/security_intel/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| """Public vulnerability-intelligence helpers for Pythinker security review. | ||
|
|
||
| This package is Python-native and intentionally independent of the blackbox MCP server runtime. | ||
| """ | ||
|
|
||
| from pythinker_review.security_intel.models import CVEIntelBundle, DependencyIntel, RiskScore | ||
|
|
||
| __all__ = ["CVEIntelBundle", "DependencyIntel", "RiskScore"] |
65 changes: 65 additions & 0 deletions
65
packages/pythinker-review/src/pythinker_review/security_intel/cache.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Small JSON TTL cache for public security-intelligence responses.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import time | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| TTL_CVE = 14_400 | ||
| TTL_SEARCH = 600 | ||
| TTL_OSV = 1_800 | ||
| TTL_EPSS = 3_600 | ||
| TTL_KEV = 21_600 | ||
| TTL_EXPLOIT = 3_600 | ||
| TTL_VENDOR = 14_400 | ||
| TTL_ATTACK = 86_400 | ||
|
|
||
| _MAX_ENTRIES = 10_000 | ||
|
|
||
|
|
||
| class IntelCache: | ||
| def __init__(self, root: Path) -> None: | ||
| self.root = root | ||
| self.path = root / "cache.json" | ||
| self._data: dict[str, dict[str, Any]] | None = None | ||
|
|
||
| def get(self, key: str) -> Any | None: | ||
| data = self._load() | ||
| entry = data.get(key) | ||
| if not entry: | ||
| return None | ||
| if float(entry.get("expires_at", 0)) < time.time(): | ||
| data.pop(key, None) | ||
| self._save(data) | ||
| return None | ||
| return entry.get("value") | ||
|
|
||
| def set(self, key: str, value: Any, ttl: int) -> None: | ||
| data = self._load() | ||
| if len(data) >= _MAX_ENTRIES: | ||
| # Keep the entries that expire latest; this is deterministic and cheap for our size cap. | ||
| survivors = sorted(data.items(), key=lambda item: item[1].get("expires_at", 0))[ | ||
| -(_MAX_ENTRIES - 1) : | ||
| ] | ||
| data = dict(survivors) | ||
| data[key] = {"value": value, "expires_at": time.time() + ttl} | ||
| self._save(data) | ||
|
|
||
| def _load(self) -> dict[str, dict[str, Any]]: | ||
| if self._data is not None: | ||
| return self._data | ||
| try: | ||
| raw = json.loads(self.path.read_text(encoding="utf-8")) | ||
| except (FileNotFoundError, OSError, json.JSONDecodeError): | ||
| raw = {} | ||
| self._data = raw if isinstance(raw, dict) else {} | ||
| return self._data | ||
|
|
||
| def _save(self, data: dict[str, dict[str, Any]]) -> None: | ||
| self.root.mkdir(parents=True, exist_ok=True) | ||
| tmp = self.path.with_suffix(".tmp") | ||
| tmp.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8") | ||
| tmp.replace(self.path) | ||
| self._data = data |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.