git-security-sentinel 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_security_sentinel/__init__.py +74 -0
- git_security_sentinel/__main__.py +9 -0
- git_security_sentinel/ai/__init__.py +17 -0
- git_security_sentinel/ai/cost.py +34 -0
- git_security_sentinel/ai/prompts.py +81 -0
- git_security_sentinel/ai_cli.py +884 -0
- git_security_sentinel/cli.py +937 -0
- git_security_sentinel/config/__init__.py +16 -0
- git_security_sentinel/config/loader.py +245 -0
- git_security_sentinel/core/__init__.py +42 -0
- git_security_sentinel/core/diff_parser.py +93 -0
- git_security_sentinel/core/models.py +111 -0
- git_security_sentinel/core/scanner.py +360 -0
- git_security_sentinel/hooks/__init__.py +8 -0
- git_security_sentinel/hooks/bootstrap.py +84 -0
- git_security_sentinel/hooks/installer.py +103 -0
- git_security_sentinel/output/__init__.py +18 -0
- git_security_sentinel/output/sarif.py +179 -0
- git_security_sentinel/py.typed +0 -0
- git_security_sentinel/redaction/__init__.py +15 -0
- git_security_sentinel/redaction/redactor.py +313 -0
- git_security_sentinel/rules/__init__.py +29 -0
- git_security_sentinel/rules/auth.py +103 -0
- git_security_sentinel/rules/catalog.py +63 -0
- git_security_sentinel/rules/cloud.py +132 -0
- git_security_sentinel/rules/compliance.py +54 -0
- git_security_sentinel/rules/database.py +87 -0
- git_security_sentinel/rules/insecure_code.py +130 -0
- git_security_sentinel/rules/sensitive_files.py +48 -0
- git_security_sentinel/suppression/__init__.py +31 -0
- git_security_sentinel/suppression/baseline.py +133 -0
- git_security_sentinel/suppression/comment_filter.py +99 -0
- git_security_sentinel/suppression/ignore_filter.py +154 -0
- git_security_sentinel/update/__init__.py +27 -0
- git_security_sentinel/update/checker.py +189 -0
- git_security_sentinel-1.2.0.dist-info/METADATA +583 -0
- git_security_sentinel-1.2.0.dist-info/RECORD +41 -0
- git_security_sentinel-1.2.0.dist-info/WHEEL +5 -0
- git_security_sentinel-1.2.0.dist-info/entry_points.txt +4 -0
- git_security_sentinel-1.2.0.dist-info/licenses/LICENSE +21 -0
- git_security_sentinel-1.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Git Security Sentinel - Deterministic Diff Security Scanner
|
|
3
|
+
Zero-dependency, privacy-first pre-commit and CI scanner for Git changes.
|
|
4
|
+
Complies with the Agent Skills Open Standard (https://agentskills.io/specification).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from git_security_sentinel.core.models import (
|
|
8
|
+
ACCEPTED_LICENSE_NAMES,
|
|
9
|
+
Finding,
|
|
10
|
+
LicenseStatus,
|
|
11
|
+
Rule,
|
|
12
|
+
SCANNER_NAME,
|
|
13
|
+
ScanReport,
|
|
14
|
+
ScanSummary,
|
|
15
|
+
SEVERITY_ORDER,
|
|
16
|
+
VERSION,
|
|
17
|
+
)
|
|
18
|
+
from git_security_sentinel.core.diff_parser import UnifiedDiffParser
|
|
19
|
+
from git_security_sentinel.core.scanner import (
|
|
20
|
+
DETECTION_RULES,
|
|
21
|
+
GitSecurityScanner,
|
|
22
|
+
IGNORE_PLACEHOLDERS,
|
|
23
|
+
is_benign_generic_value,
|
|
24
|
+
redact_text,
|
|
25
|
+
)
|
|
26
|
+
from git_security_sentinel.rules.catalog import (
|
|
27
|
+
ALL_RULES,
|
|
28
|
+
get_all_rules,
|
|
29
|
+
get_rule_by_id,
|
|
30
|
+
)
|
|
31
|
+
from git_security_sentinel.suppression import (
|
|
32
|
+
BaselineFilter,
|
|
33
|
+
PathFilter,
|
|
34
|
+
compute_fingerprint,
|
|
35
|
+
is_rule_suppressed,
|
|
36
|
+
load_sentinelignore,
|
|
37
|
+
parse_inline_suppression,
|
|
38
|
+
)
|
|
39
|
+
from git_security_sentinel.config import (
|
|
40
|
+
load_config,
|
|
41
|
+
parse_simple_yaml,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
__version__ = VERSION
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"__version__",
|
|
48
|
+
"ACCEPTED_LICENSE_NAMES",
|
|
49
|
+
"ALL_RULES",
|
|
50
|
+
"BaselineFilter",
|
|
51
|
+
"DETECTION_RULES",
|
|
52
|
+
"Finding",
|
|
53
|
+
"GitSecurityScanner",
|
|
54
|
+
"IGNORE_PLACEHOLDERS",
|
|
55
|
+
"LicenseStatus",
|
|
56
|
+
"PathFilter",
|
|
57
|
+
"Rule",
|
|
58
|
+
"SCANNER_NAME",
|
|
59
|
+
"ScanReport",
|
|
60
|
+
"ScanSummary",
|
|
61
|
+
"SEVERITY_ORDER",
|
|
62
|
+
"UnifiedDiffParser",
|
|
63
|
+
"VERSION",
|
|
64
|
+
"compute_fingerprint",
|
|
65
|
+
"get_all_rules",
|
|
66
|
+
"get_rule_by_id",
|
|
67
|
+
"is_benign_generic_value",
|
|
68
|
+
"is_rule_suppressed",
|
|
69
|
+
"load_config",
|
|
70
|
+
"load_sentinelignore",
|
|
71
|
+
"parse_inline_suppression",
|
|
72
|
+
"parse_simple_yaml",
|
|
73
|
+
"redact_text",
|
|
74
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Git Security Sentinel - AI Contextual Reviewer Engine.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from git_security_sentinel.ai.cost import (
|
|
6
|
+
PRICING_TABLE,
|
|
7
|
+
calculate_token_estimate,
|
|
8
|
+
estimate_query_cost,
|
|
9
|
+
)
|
|
10
|
+
from git_security_sentinel.ai.prompts import build_system_prompt
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"PRICING_TABLE",
|
|
14
|
+
"calculate_token_estimate",
|
|
15
|
+
"estimate_query_cost",
|
|
16
|
+
"build_system_prompt",
|
|
17
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Git Security Sentinel - AI Token Estimation and Query Cost Calculation.
|
|
3
|
+
Zero external dependencies.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict
|
|
7
|
+
|
|
8
|
+
PRICING_TABLE: Dict[str, Dict[str, float]] = {
|
|
9
|
+
"ollama": {"input": 0.0, "output": 0.0},
|
|
10
|
+
"gemini": {"input": 0.075 / 1_000_000, "output": 0.30 / 1_000_000},
|
|
11
|
+
"openai": {"input": 0.15 / 1_000_000, "output": 0.60 / 1_000_000},
|
|
12
|
+
"groq": {"input": 0.59 / 1_000_000, "output": 0.79 / 1_000_000},
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def calculate_token_estimate(prompt_text: str) -> int:
|
|
17
|
+
"""
|
|
18
|
+
Estimates token count for English code and prompts (~4 characters per token).
|
|
19
|
+
"""
|
|
20
|
+
if not prompt_text:
|
|
21
|
+
return 0
|
|
22
|
+
return max(1, len(prompt_text) // 4)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def estimate_query_cost(
|
|
26
|
+
prompt_tokens: int,
|
|
27
|
+
completion_tokens: int = 500,
|
|
28
|
+
provider: str = "ollama",
|
|
29
|
+
) -> float:
|
|
30
|
+
"""
|
|
31
|
+
Calculates estimated USD monetary cost for an AI inference query across providers.
|
|
32
|
+
"""
|
|
33
|
+
rates = PRICING_TABLE.get(provider.lower(), PRICING_TABLE["ollama"])
|
|
34
|
+
return (prompt_tokens * rates["input"]) + (completion_tokens * rates["output"])
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Git Security Sentinel - AI Reviewer System & User Prompts.
|
|
3
|
+
Includes remediation guidance for secrets and insecure code patterns (CWE).
|
|
4
|
+
Complies with the Agent Skills Open Standard (https://agentskills.io/specification).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def build_system_prompt(
|
|
11
|
+
json_mode: bool = False,
|
|
12
|
+
fix_mode: bool = False,
|
|
13
|
+
format_mode: Optional[str] = None,
|
|
14
|
+
) -> str:
|
|
15
|
+
"""
|
|
16
|
+
Constructs the system prompt for AI contextual security review.
|
|
17
|
+
Provides targeted AppSec guidance for secrets, SQL injection, pickle deserialization,
|
|
18
|
+
subprocess shell=True command injection, XXE, CORS, unverified SSL, and debug flags.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
json_mode: Whether to request structured JSON output from the LLM.
|
|
22
|
+
fix_mode: Whether to instruct the model to produce unified remediation diffs.
|
|
23
|
+
format_mode: Optional string format ('json' or 'text') for backwards compatibility.
|
|
24
|
+
"""
|
|
25
|
+
if format_mode is not None:
|
|
26
|
+
json_mode = (format_mode.lower() == "json")
|
|
27
|
+
|
|
28
|
+
prompt = (
|
|
29
|
+
"You are an expert Application Security Engineer reviewing static security scanner findings "
|
|
30
|
+
"for Git diffs. Your task is to provide concise, actionable, and contextual security triage.\n"
|
|
31
|
+
"Distinguish probable true positives from likely false positives (such as test fixtures, mocks, or benign dev configs).\n\n"
|
|
32
|
+
"Security Guidance by Pattern:\n"
|
|
33
|
+
"- SQL Injection: Recommend parameterized queries (e.g. `cursor.execute(sql, (param,))`) or ORM escaping. Never use string concatenation or f-strings.\n"
|
|
34
|
+
"- Shell Injection: Avoid `subprocess.run(..., shell=True)`. Pass argument lists and use `shlex.quote()` when shell is strictly required.\n"
|
|
35
|
+
"- Insecure Deserialization: Never load untrusted data with `pickle.loads()`. Use safe formats like `json` or `yaml.safe_load()`.\n"
|
|
36
|
+
"- XML External Entities (XXE): Disable entity resolution (`resolve_entities=False`) or use `defusedxml`.\n"
|
|
37
|
+
"- Wildcard CORS: Replace `Access-Control-Allow-Origin: *` with explicit origin whitelists.\n"
|
|
38
|
+
"- Unverified SSL: Never disable TLS verification (`verify=False`). Configure custom CA bundles instead.\n"
|
|
39
|
+
"- Debug Flags: Ensure debug modes (`DEBUG = True`) are disabled in production or gated via environment variables.\n"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if fix_mode:
|
|
43
|
+
prompt += (
|
|
44
|
+
"\nRemediation Diff Mode Enabled:\n"
|
|
45
|
+
"When requested, provide a precise suggested_fix or unified diff showing the minimal safe "
|
|
46
|
+
"code changes required to remediate the vulnerability without breaking functionality.\n"
|
|
47
|
+
"Do NOT apply changes directly to files on disk.\n"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if json_mode:
|
|
51
|
+
prompt += (
|
|
52
|
+
"\nOutput Format:\n"
|
|
53
|
+
"Respond ONLY with a single valid JSON object matching this schema:\n"
|
|
54
|
+
"{\n"
|
|
55
|
+
' "summary": "High-level summary of risks in this diff",\n'
|
|
56
|
+
' "reviews": [\n'
|
|
57
|
+
" {\n"
|
|
58
|
+
' "rule_id": "string",\n'
|
|
59
|
+
' "file": "string",\n'
|
|
60
|
+
' "line": 0,\n'
|
|
61
|
+
' "assessment": "genuine_risk | likely_false_positive | context_dependent",\n'
|
|
62
|
+
' "risk_explanation": "string",\n'
|
|
63
|
+
' "safe_alternative": "string"'
|
|
64
|
+
+ (',\n "suggested_fix_diff": "string (unified diff format)"\n' if fix_mode else '\n')
|
|
65
|
+
+ " }\n"
|
|
66
|
+
" ]\n"
|
|
67
|
+
"}\n"
|
|
68
|
+
"Return valid JSON only. Do not add markdown explanation outside the JSON.\n"
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
fix_section_title = "3. Safer Code Alternatives & Suggested Remediation Diffs" if fix_mode else "3. Safer Code Alternatives"
|
|
72
|
+
prompt += (
|
|
73
|
+
"\nOutput Format:\n"
|
|
74
|
+
"Structure your review with clear sections:\n"
|
|
75
|
+
"1. Executive Summary\n"
|
|
76
|
+
"2. Finding-by-Finding Triage & False-Positive Analysis\n"
|
|
77
|
+
f"{fix_section_title}\n"
|
|
78
|
+
"4. Immediate Recommended Actions\n"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return prompt
|