Skip to content

Commit 9d25801

Browse files
committed
fix(security): resolve explicit extensionless command paths
Signed-off-by: Narendran Raghavan <[email protected]>
1 parent 514b096 commit 9d25801

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎src/skillspector/references.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
_QUOTED_OR_CODE_PATH = re.compile(
2828
r"(?:`|'|\")((?:\./)?(?:[A-Za-z0-9_.-]+/)*[A-Za-z0-9_.-]+\.[A-Za-z0-9]{1,12})(?:`|'|\")"
2929
)
30+
# An interpreter command is an explicit path signal, but only its immediate
31+
# script operand is eligible. Searching the rest of the code span would turn
32+
# strings passed to ``-c``/``-e`` and option values into fabricated references.
33+
_INLINE_CODE_COMMAND_PATH = re.compile(
34+
r"`(?:python(?:\d+(?:\.\d+)*)?|py|node|deno|bun|bash|sh|zsh|fish|ruby|perl|php|"
35+
r"pwsh|powershell)\b[ \t]+"
36+
r"((?:\./)?(?:[A-Za-z0-9_.-]+/)+[A-Za-z0-9_.-]+)(?![\w/.-])"
37+
)
3038

3139

3240
@dataclass(frozen=True)
@@ -72,7 +80,12 @@ def _candidate_strings(
7280
"""
7381
candidates: list[tuple[str, int, int, str]] = []
7482
seen: set[tuple[int, int, str]] = set()
75-
patterns = (_MARKDOWN_DESTINATION, _QUOTED_OR_CODE_PATH, _PLAIN_RELATIVE_PATH)
83+
patterns = (
84+
_MARKDOWN_DESTINATION,
85+
_QUOTED_OR_CODE_PATH,
86+
_INLINE_CODE_COMMAND_PATH,
87+
_PLAIN_RELATIVE_PATH,
88+
)
7689
for line_number, line in enumerate(StringIO(text), 1):
7790
if clock() >= deadline:
7891
return candidates, ("runtime",)

‎tests/nodes/test_build_context.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,11 @@ def test_build_context_inventories_excluded_executable_descendants(tmp_path: Pat
10321032
"Run `python ./node_modules/pkg/loader`.",
10331033
b"import os\nprint(os.getcwd())\n",
10341034
),
1035+
(
1036+
"node_modules/pkg/loader",
1037+
"Run `python node_modules/pkg/loader`.",
1038+
b"import os\nprint(os.getcwd())\n",
1039+
),
10351040
(
10361041
".git/hooks/pre-commit.sample",
10371042
"Run `./.git/hooks/pre-commit.sample` before committing.",

‎tests/nodes/test_security_end_to_end.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,11 @@ async def test_ae1_and_incomplete_coverage_contract_across_public_surfaces(
12551255
"Run `python ./node_modules/pkg/loader`.",
12561256
"import os\nprint(os.getcwd())\n",
12571257
),
1258+
(
1259+
"node_modules/pkg/loader",
1260+
"Run `python node_modules/pkg/loader`.",
1261+
"import os\nprint(os.getcwd())\n",
1262+
),
12581263
(
12591264
".git/hooks/pre-commit.sample",
12601265
"Run `./.git/hooks/pre-commit.sample` before committing.",

‎tests/nodes/test_security_remediation.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ def test_plain_slash_separated_prose_is_not_a_reference(tmp_path: Path) -> None:
358358
source_path="SKILL.md",
359359
source_text=(
360360
"Compare reads/writes, environment/profile settings, operation/node behavior, "
361-
"and model/provider options. SkillSpector 2.10.0 supports node.js; see example.com."
361+
"and model/provider options, including `request/response` terminology. "
362+
"SkillSpector 2.10.0 supports node.js; see example.com."
362363
),
363364
known_paths=["SKILL.md"],
364365
)
@@ -389,6 +390,41 @@ def test_plain_local_reference_requires_an_explicit_path_signal(
389390
assert records[0]["target_path"] == target_path
390391

391392

393+
@pytest.mark.parametrize("path", ["./node_modules/pkg/loader", "node_modules/pkg/loader"])
394+
def test_inline_command_resolves_extensionless_nested_path(tmp_path: Path, path: str) -> None:
395+
records = resolve_bundle_references(
396+
tmp_path,
397+
source_path="SKILL.md",
398+
source_text=f"Run `python {path}`.",
399+
known_paths=["SKILL.md", "node_modules/pkg/loader"],
400+
)
401+
402+
assert len(records) == 1
403+
assert records[0]["status"] == "resolved"
404+
assert records[0]["target_path"] == "node_modules/pkg/loader"
405+
406+
407+
@pytest.mark.parametrize(
408+
"source_text",
409+
[
410+
'`python -c "print(\\"request/response\\")"`',
411+
"`python --config=request/response`",
412+
"`node -e 'console.log(\"request/response\")'`",
413+
],
414+
)
415+
def test_inline_command_does_not_extract_paths_from_code_or_options(
416+
tmp_path: Path, source_text: str
417+
) -> None:
418+
records = resolve_bundle_references(
419+
tmp_path,
420+
source_path="SKILL.md",
421+
source_text=source_text,
422+
known_paths=["SKILL.md", "request/response"],
423+
)
424+
425+
assert records == []
426+
427+
392428
def test_reference_resolver_rejects_external_and_parent_escape(tmp_path: Path) -> None:
393429
records = resolve_bundle_references(
394430
tmp_path,

0 commit comments

Comments
 (0)