Skip to content
Closed
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 kernelguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,13 @@ def detect_precision_downgrade(code: str | SubmissionFacts) -> list[dict]:


# ---------------------------------------------------------------------------
RE_IO_STREAM = re.compile(r'io\.(?:StringIO|BytesIO)\s*\(')
def detect_io_stream_output(code: str | SubmissionFacts) -> list[dict]:
facts = ensure_submission_facts(code)
if not RE_IO_STREAM.search(facts.raw_code): return []
return [{"pattern": "STDIO_REDIRECT", "severity": "medium", "evidence": "io.StringIO/BytesIO — in-memory stream for output injection/manipulation"}]


# Score anomaly detection
# ---------------------------------------------------------------------------

Expand Down Expand Up @@ -3790,6 +3797,7 @@ def support_only_patterns(matched_patterns: list[dict]) -> bool:
detect_thread_injection,
detect_lazy_tensor,
detect_precision_downgrade,
detect_logging_output_injection,
]

BASE_DETECTOR_SPECS = [
Expand Down Expand Up @@ -3827,6 +3835,7 @@ def support_only_patterns(matched_patterns: list[dict]) -> bool:
("thread_injection", detect_thread_injection),
("lazy_tensor", detect_lazy_tensor),
("precision_downgrade", detect_precision_downgrade),
("io_stream_output", detect_io_stream_output),
]

VALID_RULE_OUTCOMES = {AUTO_FILTER, SUSPICIOUS_ONLY, TELEMETRY_ONLY}
Expand Down