Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
10923e0
fix(security): normalize concealed instruction text
Spectorian Aug 21, 2026
057fd7b
fix(security): detect inter-character text obfuscation
Spectorian Aug 21, 2026
d8c3213
test(security): cover ambiguous spaced instructions
Spectorian Aug 21, 2026
e6a96df
fix(security): bound stable Unicode projection
Spectorian Aug 21, 2026
1d50da6
fix(security): fail closed on obfuscated instructions
Spectorian Aug 22, 2026
b10b82e
Merge branch 'main' into codex/security-text-normalization
github-actions[bot] Aug 24, 2026
2d346c0
Merge branch 'main' into codex/security-text-normalization
rng1995 Aug 24, 2026
41bcdaf
Merge branch 'main' into codex/security-text-normalization
github-actions[bot] Aug 24, 2026
42f0b4f
Merge branch 'main' into codex/security-text-normalization
github-actions[bot] Aug 24, 2026
cc393ef
Merge branch 'main' into codex/security-text-normalization
github-actions[bot] Aug 24, 2026
1210b82
fix: harden concealed instruction detection
Spectorian Aug 24, 2026
3112c49
fix(security): fail closed on boundary concealment
Spectorian Aug 25, 2026
c0b233a
perf(security): skip irrelevant boundary scans
Spectorian Aug 25, 2026
3d89803
fix(security): broaden concealed command evidence
Spectorian Aug 25, 2026
3a2fb1b
fix(security): detect declared-marker obfuscation
mohgupta-ship-it Aug 26, 2026
db49fd8
fix(security): harden deterministic obfuscation analysis
mohgupta-ship-it Aug 30, 2026
057000d
Merge branch 'main' into codex/security-text-normalization
github-actions[bot] Aug 25, 2026
4e20377
Merge pull request #437 from NVIDIA/codex/security-hybrid-obfuscation
mohgupta-ship-it Aug 30, 2026
41eea29
fix(security): harden obfuscation controls after rebase
mohgupta-ship-it Aug 30, 2026
ede4176
fix(security): close obfuscation CI gaps
mohgupta-ship-it Aug 30, 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
404 changes: 395 additions & 9 deletions src/skillspector/artifacts.py

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/skillspector/inspection_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class LedgerReason(StrEnum):
TOTAL_BYTES_LIMIT = "total_bytes_limit"
RUNTIME_LIMIT = "runtime_limit"
OUTPUT_LIMIT = "output_limit"
OBFUSCATED_INSTRUCTION_TEXT = "obfuscated_instruction_text"


REASON_MESSAGES: Final[dict[LedgerReason, str]] = {
Expand Down Expand Up @@ -176,6 +177,10 @@ class LedgerReason(StrEnum):
LedgerReason.TOTAL_BYTES_LIMIT: "Bundle caching reached its aggregate byte limit.",
LedgerReason.RUNTIME_LIMIT: "Inspection reached its configured runtime limit.",
LedgerReason.OUTPUT_LIMIT: "Inspection reached its configured output limit.",
LedgerReason.OBFUSCATED_INSTRUCTION_TEXT: (
"Instruction text obfuscated by inter-character spacing could not be fully evaluated "
"by the deterministic layer."
),
}


Expand Down
164 changes: 160 additions & 4 deletions src/skillspector/nodes/analyzers/artifact_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@

import time
import unicodedata
from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass, field

from skillspector.artifacts import (
_concealed_instruction_run_spans,
_contextual_default_ignorable_boundary_spans,
)
from skillspector.inspection_ledger import (
InspectionLedgerEvent,
LedgerOutcome,
LedgerReason,
LedgerRecordType,
analyzer_status_for_events,
ledger_event,
)
Expand All @@ -34,6 +41,23 @@
)
_RUNTIME_CHECK_INTERVAL_CHARS = 4096
_ALLOWED_FORMAT_CHARACTERS = frozenset({"\n", "\r", "\t"})
_LETTER_SPACING_SECURITY_TERMS = (
Comment thread
mohgupta-ship-it marked this conversation as resolved.
Resolved
"bypass",
"disregard",
"ignore",
"instructions",
"jailbreak",
"override",
"previousinstructions",
"restrictions",
"securityconstraints",
"silentlysend",
"sshkey",
"unfiltered",
"unrestricted",
"userdata",
)
_MAX_LETTER_SPACING_SECURITY_TERM = max(map(len, _LETTER_SPACING_SECURITY_TERMS))


class _ArtifactIntegrityResourceLimitError(RuntimeError):
Expand Down Expand Up @@ -99,10 +123,94 @@ def analyzer_exhausted(self) -> bool:
return len(self.findings) >= MAX_FINDINGS_PER_ANALYZER


def _spacing_span_has_security_term(
content: str,
span: tuple[int, int],
budget: _ArtifactIntegrityBudget,
) -> bool:
"""Match security-relevant condensed terms without retaining the full run."""
overlap = ""
letters: list[str] = []
letter_characters = 0
for offset in range(*span):
if offset % _RUNTIME_CHECK_INTERVAL_CHARS == 0:
budget.check_runtime()
character = content[offset]
if not character.isalpha():
continue
folded = character.casefold()
Comment thread
mohgupta-ship-it marked this conversation as resolved.
Resolved
letters.append(folded)
letter_characters += len(folded)
if letter_characters < _RUNTIME_CHECK_INTERVAL_CHARS:
continue
block = overlap + "".join(letters)
if any(term in block for term in _LETTER_SPACING_SECURITY_TERMS):
Comment thread
mohgupta-ship-it marked this conversation as resolved.
Resolved
return True
overlap = block[-(_MAX_LETTER_SPACING_SECURITY_TERM - 1) :]
letters.clear()
letter_characters = 0

block = overlap + "".join(letters)
return any(term in block for term in _LETTER_SPACING_SECURITY_TERMS)


def _matching_security_term_raw_spans(
projection: deque[str],
raw_offsets: deque[int],
) -> Iterator[tuple[int, int]]:
"""Yield raw envelopes for terms ending in a bounded projection."""
normalized = "".join(projection)
for term in _LETTER_SPACING_SECURITY_TERMS:
if normalized.endswith(term):
yield raw_offsets[-len(term)], raw_offsets[-1] + 1


def _contextual_ignorable_security_line(
content: str,
budget: _ArtifactIntegrityBudget,
) -> int | None:
"""Return the first boundary gap that touches a security-term match."""
spans = iter(
_contextual_default_ignorable_boundary_spans(
content,
budget.check_runtime,
)
)
next_span = next(spans, None)
latest_span: tuple[int, int] | None = None
projection: deque[str] = deque(maxlen=_MAX_LETTER_SPACING_SECURITY_TERM)
raw_offsets: deque[int] = deque(maxlen=_MAX_LETTER_SPACING_SECURITY_TERM)

for offset, character in enumerate(content):
if offset % _RUNTIME_CHECK_INTERVAL_CHARS == 0:
budget.check_runtime()
if not character.isalpha():
continue
for folded in character.casefold():
if not folded.isalpha():
continue
projection.append(folded)
raw_offsets.append(offset)
term_end = offset + 1
while next_span is not None and next_span[0] <= term_end:
latest_span = next_span
next_span = next(spans, None)
if latest_span is None:
continue
for term_start, matched_term_end in _matching_security_term_raw_spans(
projection,
raw_offsets,
):
if latest_span[0] <= matched_term_end and latest_span[1] >= term_start:
budget.check_runtime()
return content.count("\n", 0, latest_span[0]) + 1
return None


def _text_signals(
content: str,
budget: _ArtifactIntegrityBudget,
) -> tuple[float, bool, int | None]:
) -> tuple[float, bool, int | None, int | None]:
"""Derive Unicode and NUL signals with cooperative deadline checks.

Only counters, a three-entry script set, and the first NUL line are kept;
Expand All @@ -113,6 +221,27 @@ def _text_signals(
token_scripts: set[str] = set()
line = 1
first_nul_line: int | None = None
spacing_span = next(
(
span
for span in _concealed_instruction_run_spans(
content,
budget.check_runtime,
)
if _spacing_span_has_security_term(content, span, budget)
),
None,
)
first_spacing_line = (
content.count("\n", 0, spacing_span[0]) + 1 if spacing_span is not None else None
)
first_contextual_ignorable_line = _contextual_ignorable_security_line(content, budget)
obfuscation_lines = [
value
for value in (first_spacing_line, first_contextual_ignorable_line)
if value is not None
]
first_obfuscation_line = min(obfuscation_lines, default=None)

for index, character in enumerate(content):
if index % _RUNTIME_CHECK_INTERVAL_CHARS == 0:
Expand Down Expand Up @@ -146,7 +275,7 @@ def _text_signals(
budget.check_runtime()
mixed_script = mixed_script or ("latin" in token_scripts and len(token_scripts) > 1)
density = ignored_characters / len(content) if content else 0.0
return density, mixed_script, first_nul_line
return density, mixed_script, first_nul_line, first_obfuscation_line


def _partial_limit_event(
Expand Down Expand Up @@ -241,6 +370,7 @@ def node(state: SkillspectorState) -> AnalyzerNodeResponse:
artifact: dict[str, object] = raw_artifact if isinstance(raw_artifact, dict) else {}
finding_start = len(budget.findings)
resource_limit: _ArtifactIntegrityResourceLimitError | None = None
first_obfuscation_line: int | None = None
try:
budget.check_runtime()
if artifact.get("misleading_extension"):
Expand Down Expand Up @@ -269,7 +399,9 @@ def node(state: SkillspectorState) -> AnalyzerNodeResponse:
confidence=1.0,
)
)
format_density, mixed_script, first_nul_line = _text_signals(content, budget)
format_density, mixed_script, first_nul_line, first_obfuscation_line = (
_text_signals(content, budget)
)
if artifact.get("contains_nul") and first_nul_line is not None:
budget.emit(
_finding(
Expand All @@ -291,6 +423,17 @@ def node(state: SkillspectorState) -> AnalyzerNodeResponse:
confidence=0.8,
)
)
if first_obfuscation_line is not None:
budget.emit(
_finding(
"AE6",
"Instruction text uses inter-character separators to evade pattern matching",
path,
severity="HIGH",
confidence=0.9,
line=first_obfuscation_line,
)
)
except _ArtifactIntegrityResourceLimitError as exc:
resource_limit = exc

Expand All @@ -308,8 +451,21 @@ def node(state: SkillspectorState) -> AnalyzerNodeResponse:
emitted_finding_ids=emitted_ids,
)
events.append(event)
if resource_limit is None and first_obfuscation_line is not None:
events.append(
ledger_event(
outcome=LedgerOutcome.PARTIAL,
phase="artifact_interpretation",
path=path,
start_line=first_obfuscation_line,
end_line=first_obfuscation_line,
record_type=LedgerRecordType.SYSTEM,
reason=LedgerReason.OBFUSCATED_INSTRUCTION_TEXT,
)
)
work_events = (event for event in events if event["record_type"] == LedgerRecordType.WORK_ITEM)
return {
"findings": budget.findings,
"inspection_ledger": events,
"analyzer_status_events": [analyzer_status_for_events(ANALYZER_ID, events)],
"analyzer_status_events": [analyzer_status_for_events(ANALYZER_ID, work_events)],
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import re
import sys

from skillspector.artifacts import _is_emoji_base
from skillspector.logging_config import get_logger
from skillspector.models import AnalyzerFinding, Location, Severity
from skillspector.state import AnalyzerNodeResponse, SkillspectorState
Expand Down Expand Up @@ -173,15 +174,6 @@ def _is_p9_skipped_path(file_path: str) -> bool:
_VARIATION_SELECTORS = {0xFE0E, 0xFE0F}


def _is_emoji_base(ch: str) -> bool:
codepoint = ord(ch)
return (
0x1F000 <= codepoint <= 0x1FAFF
or 0x2600 <= codepoint <= 0x27BF
or codepoint in (0x00A9, 0x00AE, 0x203C, 0x2049, 0x2122, 0x2139, 0x3030, 0x303D)
)


def _previous_emoji_base(content: str, offset: int) -> bool:
i = offset - 1
while i >= 0 and (
Expand Down
22 changes: 17 additions & 5 deletions src/skillspector/nodes/analyzers/static_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
from dataclasses import dataclass, field
from typing import cast

from skillspector.artifacts import ContentKind, SecurityTextView, security_text_views
from skillspector.artifacts import (
ContentKind,
SecurityTextView,
is_default_ignorable,
security_text_views,
)
from skillspector.inspection_ledger import (
InspectionLedgerEvent,
LedgerOutcome,
Expand Down Expand Up @@ -85,6 +90,7 @@
_LICENSE_BASENAME = re.compile(r"^(?:license|licenses|copying|notice|notices)(?:[._-].*)?$")
_LICENSE_OTHER_SUFFIXES = frozenset({".lesser"})
_ASCII_CONTINUITY_SEPARATOR_RUN = re.compile(r"[\s\x00-\x08\x0b\x0c\x0e-\x1f\x7f]+")
_ASCII_NON_NEWLINE_WHITESPACE = re.compile(r"[ \t\r\f\v]")


def _normalize_license_line(line: str) -> str:
Expand Down Expand Up @@ -539,6 +545,7 @@ def _is_continuity_separator(character: str) -> bool:
character.isspace()
or character == "\u00ad"
or character == "\ufffd"
or is_default_ignorable(character)
or unicodedata.category(character) in {"Cf", "Cc"}
)

Expand Down Expand Up @@ -599,10 +606,11 @@ def _continuity_views(

Separator runs wider than the normal overlap can otherwise place two
adjacent lexical tokens in different windows. Retaining up to 8 KiB of
the original run preserves newlines and keeps every bounded-gap expression
bounded, while expressions that already accept an unbounded separator see
the same token sequence. The source-line map is constructed per view, so
neither a whole-file normalized copy nor a whole-file offset table exists.
the original run preserves ASCII whitespace boundaries and newlines while
keeping every bounded-gap expression bounded. Expressions that already
accept an unbounded separator see the same token sequence. The source-line
map is constructed per view, so neither a whole-file normalized copy nor a
whole-file offset table exists.
"""
separator_runs = list(_continuity_separator_runs(content, finding_budget))
previous_left = 0
Expand Down Expand Up @@ -659,6 +667,10 @@ def _continuity_views(
text_parts.append("\n")
current_line += skipped_newlines
source_lines.append(current_line)
elif _ASCII_NON_NEWLINE_WHITESPACE.search(content, head_end, tail_start):
# Never let truncation erase a real word boundary and turn
# separated tokens into a normalized security match.
text_parts.append(" ")
current_line = _append_projected_piece(
text_parts,
source_lines,
Expand Down
18 changes: 18 additions & 0 deletions tests/nodes/analyzers/test_artifact_integrity_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ def test_deadline_during_content_marks_current_and_remaining_partial() -> None:
assert result["analyzer_status_events"][0]["status"] == "degraded"


def test_deadline_inside_large_separator_gap_marks_artifact_partial() -> None:
workflow_budget = _ExpiringWorkflowBudget(5)
content = "i" + "." * 300_000 + "g.n.o.r.e"

result = artifact_integrity.node(
{
"components": ["SKILL.md"],
"local_file_cache": {"SKILL.md": content},
"artifact_inventory": [{"path": "SKILL.md"}],
"workflow_resource_budget": workflow_budget,
}
)

assert result["inspection_ledger"][0]["outcome"] == "partial"
assert result["inspection_ledger"][0]["reason_code"] == "runtime_limit"
assert result["analyzer_status_events"][0]["status"] == "degraded"


def test_finding_cap_stops_construction_and_marks_affected_suffix_partial(
monkeypatch,
) -> None:
Expand Down
Loading
Loading