timecs 2.0.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.
- app.py +3014 -0
- ast_scanner.py +36187 -0
- banner.py +146 -0
- ci_reporter.py +570 -0
- cli.py +2347 -0
- config_loader.py +307 -0
- cross_file_engine.py +1781 -0
- delivery_models.py +145 -0
- delivery_repository.py +78 -0
- diff_scan.py +127 -0
- durable_delivery_sink.py +103 -0
- event_bus.py +155 -0
- event_publisher.py +345 -0
- event_taxonomy.py +313 -0
- function_summarizer.py +354 -0
- html_auditor.py +274 -0
- iac_auditor.py +400 -0
- in_app_adapter.py +115 -0
- js_scanner.py +895 -0
- manifest_parser.py +960 -0
- master_rules_bank.py +389 -0
- notification_models.py +346 -0
- notification_policy.py +309 -0
- notification_repository.py +118 -0
- notification_routes.py +394 -0
- notification_service.py +199 -0
- osv_client.py +437 -0
- remediation/__init__.py +39 -0
- remediation/base.py +102 -0
- remediation/contracts.py +196 -0
- remediation/cwe1188_binding.py +78 -0
- remediation/cwe1336_jinja.py +91 -0
- remediation/cwe22_path_traversal.py +348 -0
- remediation/cwe295_ssl.py +87 -0
- remediation/cwe327_weak_hash.py +78 -0
- remediation/cwe377_tempfile.py +77 -0
- remediation/cwe489_debug.py +80 -0
- remediation/cwe502_yaml.py +89 -0
- remediation/cwe614_cookie.py +91 -0
- remediation/cwe78_cmdi.py +415 -0
- remediation/cwe798_credentials.py +153 -0
- remediation/cwe89_sqli.py +425 -0
- remediation/cwe916_password_hash.py +131 -0
- remediation/cwe95_eval.py +77 -0
- remediation/dispatcher.py +114 -0
- remediation/orchestrator.py +541 -0
- remediation/patch_engine.py +213 -0
- remediation/verification.py +253 -0
- rule_engine.py +1535 -0
- sarif_adapter.py +719 -0
- sarif_exporter.py +88 -0
- sca_reachability/__init__.py +28 -0
- sca_reachability/ast_analyzer.py +366 -0
- sca_reachability/call_graph.py +203 -0
- sca_reachability/contracts.py +365 -0
- sca_reachability/dist_import_map.py +46 -0
- sca_reachability/engine.py +603 -0
- sca_reachability/resolver.py +169 -0
- scanners/__init__.py +70 -0
- scanners/container_scanner.py +323 -0
- scanners/cve_index.py +521 -0
- scanners/iac_scanner.py +328 -0
- scanners/sbom.py +183 -0
- scanners/sca_scanner.py +667 -0
- scanners/secret_scanner.py +345 -0
- scanners/yaml_lite.py +217 -0
- secret_filters.py +435 -0
- secret_scanner.py +943 -0
- sqlite_delivery_repository.py +277 -0
- sqlite_notification_repository.py +441 -0
- ssrf_guard.py +276 -0
- staged_scanner.py +492 -0
- suppression_resolver.py +282 -0
- symbol_indexer.py +424 -0
- tcs/__init__.py +1 -0
- tcs/analysis/__init__.py +1 -0
- tcs/analysis/def_use.py +408 -0
- tcs/analysis/function_contracts.py +290 -0
- tcs/parallel_analyzer.py +276 -0
- tcs/parallel_scanner.py +630 -0
- tcs/treesitter_packer.py +1446 -0
- tcs_cli.py +2086 -0
- tcs_config.py +218 -0
- tcs_gui.py +2123 -0
- timecs-2.0.0.dist-info/METADATA +142 -0
- timecs-2.0.0.dist-info/RECORD +94 -0
- timecs-2.0.0.dist-info/WHEEL +5 -0
- timecs-2.0.0.dist-info/entry_points.txt +4 -0
- timecs-2.0.0.dist-info/licenses/LICENSE +201 -0
- timecs-2.0.0.dist-info/top_level.txt +49 -0
- version_matcher.py +934 -0
- webhook_adapter.py +495 -0
- webhook_client.py +483 -0
- webhook_formatters.py +245 -0
webhook_formatters.py
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TimeCodeSecurity Webhook Payload Formatters & Sanitization.
|
|
3
|
+
|
|
4
|
+
Defines:
|
|
5
|
+
- MAX_WEBHOOK_PAYLOAD_BYTES = 65536 (Universal 64 KB ceiling).
|
|
6
|
+
- GenericWebhookFormatter: Standard JSON schema with schema_version: 1.
|
|
7
|
+
- SlackWebhookFormatter: Block Kit format with XML entity escaping and mention neutralization.
|
|
8
|
+
- DiscordWebhookFormatter: Embed format with markdown sanitization and mention neutralization.
|
|
9
|
+
- PayloadTooLargeError: Raised before network transmission if bytes > 65536.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
from typing import Any, Dict, List, Optional
|
|
16
|
+
|
|
17
|
+
from notification_policy import NotificationIntent, SafeFindingSummary
|
|
18
|
+
|
|
19
|
+
MAX_WEBHOOK_PAYLOAD_BYTES = 65536 # 64 KB exact ceiling
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class PayloadTooLargeError(Exception):
|
|
23
|
+
"""Raised when serialized webhook payload exceeds MAX_WEBHOOK_PAYLOAD_BYTES before network transmission."""
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def escape_slack_text(text: str) -> str:
|
|
28
|
+
"""
|
|
29
|
+
Escapes Slack mrkdwn control characters in untrusted strings:
|
|
30
|
+
- & -> &
|
|
31
|
+
- < -> <
|
|
32
|
+
- > -> >
|
|
33
|
+
This neutralizes mention injections (<@U123>, <!everyone>, <!here>).
|
|
34
|
+
"""
|
|
35
|
+
if not text:
|
|
36
|
+
return ""
|
|
37
|
+
return (
|
|
38
|
+
text.replace("&", "&")
|
|
39
|
+
.replace("<", "<")
|
|
40
|
+
.replace(">", ">")
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def escape_discord_text(text: str) -> str:
|
|
45
|
+
"""
|
|
46
|
+
Sanitizes untrusted text for Discord embeds:
|
|
47
|
+
- Injects zero-width space into @everyone and @here
|
|
48
|
+
- Injects zero-width space into raw mention syntax (<@, <@&)
|
|
49
|
+
"""
|
|
50
|
+
if not text:
|
|
51
|
+
return ""
|
|
52
|
+
sanitized = text.replace("@everyone", "@\u200beveryone").replace("@here", "@\u200bhere")
|
|
53
|
+
sanitized = sanitized.replace("<@", "<\u200b@").replace("<@&", "<\u200b@&")
|
|
54
|
+
return sanitized
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class GenericWebhookFormatter:
|
|
58
|
+
"""
|
|
59
|
+
Default JSON payload formatter.
|
|
60
|
+
Enforces schema_version: 1 and strict 64 KB ceiling.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def format(intent: NotificationIntent) -> bytes:
|
|
65
|
+
findings_payload: List[Dict[str, Any]] = [
|
|
66
|
+
{
|
|
67
|
+
"rule_id": f.rule_id,
|
|
68
|
+
"cwe": f.cwe,
|
|
69
|
+
"severity": f.severity,
|
|
70
|
+
"file_path": f.file_path,
|
|
71
|
+
"line": f.line,
|
|
72
|
+
"message": f.message,
|
|
73
|
+
}
|
|
74
|
+
for f in intent.safe_findings
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
payload_obj = {
|
|
78
|
+
"schema_version": 1,
|
|
79
|
+
"event_id": intent.event_id,
|
|
80
|
+
"scan_id": intent.scan_id,
|
|
81
|
+
"organization_id": intent.organization_id,
|
|
82
|
+
"notification_type": intent.notification_type,
|
|
83
|
+
"severity": intent.severity,
|
|
84
|
+
"title": intent.title,
|
|
85
|
+
"message": intent.message,
|
|
86
|
+
"link": intent.link,
|
|
87
|
+
"created_at": intent.created_at,
|
|
88
|
+
"findings_truncated": intent.findings_truncated,
|
|
89
|
+
"total_findings": intent.total_findings,
|
|
90
|
+
"findings": findings_payload,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
payload_bytes = json.dumps(payload_obj, ensure_ascii=False, indent=None).encode("utf-8")
|
|
94
|
+
if len(payload_bytes) > MAX_WEBHOOK_PAYLOAD_BYTES:
|
|
95
|
+
raise PayloadTooLargeError(
|
|
96
|
+
f"Generic webhook payload exceeds {MAX_WEBHOOK_PAYLOAD_BYTES} bytes ({len(payload_bytes)} bytes)."
|
|
97
|
+
)
|
|
98
|
+
return payload_bytes
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class SlackWebhookFormatter:
|
|
102
|
+
"""
|
|
103
|
+
Formats NotificationIntent into Slack Block Kit payload.
|
|
104
|
+
Escapes all dynamic text and enforces section/block limits.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
@staticmethod
|
|
108
|
+
def format(intent: NotificationIntent) -> bytes:
|
|
109
|
+
safe_title = escape_slack_text(intent.title)[:2000]
|
|
110
|
+
safe_msg = escape_slack_text(intent.message)[:2000]
|
|
111
|
+
safe_sev = escape_slack_text(intent.severity)
|
|
112
|
+
|
|
113
|
+
blocks: List[Dict[str, Any]] = [
|
|
114
|
+
{
|
|
115
|
+
"type": "header",
|
|
116
|
+
"text": {
|
|
117
|
+
"type": "plain_text",
|
|
118
|
+
"text": safe_title[:150],
|
|
119
|
+
"emoji": True,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"type": "section",
|
|
124
|
+
"text": {
|
|
125
|
+
"type": "mrkdwn",
|
|
126
|
+
"text": f"*Severity:* `{safe_sev}`\n{safe_msg}",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
# Add findings summary blocks (up to 10 findings, max 15 total blocks)
|
|
132
|
+
for idx, finding in enumerate(intent.safe_findings[:10]):
|
|
133
|
+
f_rule = escape_slack_text(finding.rule_id)
|
|
134
|
+
f_cwe = escape_slack_text(finding.cwe)
|
|
135
|
+
f_path = escape_slack_text(finding.file_path)
|
|
136
|
+
f_line = f":{finding.line}" if finding.line else ""
|
|
137
|
+
f_msg = escape_slack_text(finding.message)
|
|
138
|
+
|
|
139
|
+
block_text = f"• *{f_rule}* ({f_cwe}) [{finding.severity}]\n `{f_path}{f_line}` — {f_msg}"
|
|
140
|
+
blocks.append({
|
|
141
|
+
"type": "section",
|
|
142
|
+
"text": {
|
|
143
|
+
"type": "mrkdwn",
|
|
144
|
+
"text": block_text[:2000],
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
if len(blocks) >= 14:
|
|
148
|
+
break
|
|
149
|
+
|
|
150
|
+
if intent.findings_truncated or intent.total_findings > len(intent.safe_findings):
|
|
151
|
+
blocks.append({
|
|
152
|
+
"type": "context",
|
|
153
|
+
"elements": [
|
|
154
|
+
{
|
|
155
|
+
"type": "mrkdwn",
|
|
156
|
+
"text": f"Showing {len(intent.safe_findings)} of {intent.total_findings} findings. View full scan in dashboard.",
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
payload_obj = {
|
|
162
|
+
"text": safe_title[:2000],
|
|
163
|
+
"blocks": blocks[:15],
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
payload_bytes = json.dumps(payload_obj, ensure_ascii=False).encode("utf-8")
|
|
167
|
+
if len(payload_bytes) > MAX_WEBHOOK_PAYLOAD_BYTES:
|
|
168
|
+
raise PayloadTooLargeError(
|
|
169
|
+
f"Slack webhook payload exceeds {MAX_WEBHOOK_PAYLOAD_BYTES} bytes ({len(payload_bytes)} bytes)."
|
|
170
|
+
)
|
|
171
|
+
return payload_bytes
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class DiscordWebhookFormatter:
|
|
175
|
+
"""
|
|
176
|
+
Formats NotificationIntent into Discord Embed payload.
|
|
177
|
+
Sanitizes markdown and neutralizes mass mentions (@everyone, @here).
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
@staticmethod
|
|
181
|
+
def format(intent: NotificationIntent) -> bytes:
|
|
182
|
+
safe_title = escape_discord_text(intent.title)[:250]
|
|
183
|
+
safe_desc = escape_discord_text(intent.message)[:2000]
|
|
184
|
+
|
|
185
|
+
# Severity color mapping
|
|
186
|
+
colors = {
|
|
187
|
+
"CRITICAL": 0xFF0000, # Red
|
|
188
|
+
"HIGH": 0xFF5500, # Orange
|
|
189
|
+
"MEDIUM": 0xFFAA00, # Amber
|
|
190
|
+
"LOW": 0x00AAFF, # Light Blue
|
|
191
|
+
"INFO": 0x888888, # Grey
|
|
192
|
+
}
|
|
193
|
+
color = colors.get(intent.severity.upper(), 0x888888)
|
|
194
|
+
|
|
195
|
+
fields: List[Dict[str, Any]] = [
|
|
196
|
+
{"name": "Severity", "value": f"`{intent.severity}`", "inline": True},
|
|
197
|
+
{"name": "Total Findings", "value": str(intent.total_findings), "inline": True},
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
for finding in intent.safe_findings[:5]:
|
|
201
|
+
f_rule = escape_discord_text(finding.rule_id)[:64]
|
|
202
|
+
f_path = escape_discord_text(finding.file_path)[:128]
|
|
203
|
+
f_line = f":{finding.line}" if finding.line else ""
|
|
204
|
+
f_msg = escape_discord_text(finding.message)[:255]
|
|
205
|
+
fields.append({
|
|
206
|
+
"name": f"{f_rule} [{finding.severity}]",
|
|
207
|
+
"value": f"`{f_path}{f_line}`\n{f_msg}",
|
|
208
|
+
"inline": False,
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
embed = {
|
|
212
|
+
"title": safe_title,
|
|
213
|
+
"description": safe_desc,
|
|
214
|
+
"color": color,
|
|
215
|
+
"fields": fields,
|
|
216
|
+
}
|
|
217
|
+
if intent.link:
|
|
218
|
+
embed["url"] = intent.link
|
|
219
|
+
|
|
220
|
+
payload_obj = {
|
|
221
|
+
"content": safe_title[:2000],
|
|
222
|
+
"text": safe_title[:2000],
|
|
223
|
+
"embeds": [embed]
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
payload_bytes = json.dumps(payload_obj, ensure_ascii=False).encode("utf-8")
|
|
227
|
+
if len(payload_bytes) > MAX_WEBHOOK_PAYLOAD_BYTES:
|
|
228
|
+
raise PayloadTooLargeError(
|
|
229
|
+
f"Discord webhook payload exceeds {MAX_WEBHOOK_PAYLOAD_BYTES} bytes ({len(payload_bytes)} bytes)."
|
|
230
|
+
)
|
|
231
|
+
return payload_bytes
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def format_webhook_payload(intent: NotificationIntent, format_type: str = "GENERIC") -> bytes:
|
|
235
|
+
"""
|
|
236
|
+
Factory function formatting a NotificationIntent into wire bytes
|
|
237
|
+
using the specified format ("GENERIC", "SLACK", or "DISCORD").
|
|
238
|
+
"""
|
|
239
|
+
fmt = format_type.upper().strip()
|
|
240
|
+
if fmt == "SLACK":
|
|
241
|
+
return SlackWebhookFormatter.format(intent)
|
|
242
|
+
elif fmt == "DISCORD":
|
|
243
|
+
return DiscordWebhookFormatter.format(intent)
|
|
244
|
+
else:
|
|
245
|
+
return GenericWebhookFormatter.format(intent)
|