pyddock 0.3.2__tar.gz → 0.3.3__tar.gz
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.
- {pyddock-0.3.2 → pyddock-0.3.3}/PKG-INFO +1 -1
- {pyddock-0.3.2 → pyddock-0.3.3}/pyproject.toml +1 -1
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_base.py +36 -17
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_fs_enforcement.py +28 -5
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/default_config.toml +2 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/shell_executor.py +22 -11
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_jailbreak_regression.py +38 -3
- {pyddock-0.3.2 → pyddock-0.3.3}/uv.lock +1 -1
- {pyddock-0.3.2 → pyddock-0.3.3}/.gitignore +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/.gitignore +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/106d94c8123c0256 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/1685e03b3aa38c02 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/1deca112ec6f2f3c +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/2488a3a95c48acfb +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/2a94d83a13979745 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/499f1d5a639a382a +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/4ee6f24fa151b65d +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/5b1b2189b70f5ef2 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/5d6f8b26b2137fe1 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/61f9b905d7da14e0 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/67a7f4ab2d372f23 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/6c6f5083ece3f86b +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/827e18b40f235443 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/8401e4039d635fbc +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/8490e7baefc8c8c3 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/a7c132b836381d0d +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/b395547bc71e5c52 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/constants/ca50661510a40488 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/tmp/tmpl8oe65gb +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/tmp/tmpqwper0dp +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/unicode_data/15.1.0/charmap.json.gz +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/.hypothesis/unicode_data/15.1.0/codec-utf-8.json.gz +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/LICENSE +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/README.md +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/publish-to-pypi.ps1 +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/__init__.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_audit_enforcement.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_enforcement.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_import_hook.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_prewarm.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_process_utils.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_proxies.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_runtime.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/_subprocess_patch.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/ast_validator.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/cli.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/config.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/executor.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/script_registry.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/server.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/tools/__init__.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/tools/fs_append.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/tools/fs_delete.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/tools/read_file.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/tools/stat_file.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/tools/str_replace.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/src/pyddock/venv_manager.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/__init__.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/_config_helpers.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_ast_properties.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_attr_reflection_hardening.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_audit_hook_backstop.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_chmod_integration.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_config.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_deny_always_wins.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_deny_messages.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_env_policy.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_executor.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_file_tools.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_filesystem_guards.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_proxy_properties.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_realistic.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_runtime.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_sandbox_escape_hardening.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_security_guards.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_server.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_shell_arg_paths.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_shell_executor.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_shell_properties.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_subprocess_enforcement.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_subprocess_properties.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_subst_trusted_path.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_trusted_prefixes_uv_cache.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_venv_stamp.py +0 -0
- {pyddock-0.3.2 → pyddock-0.3.3}/tests/test_workspace_imports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyddock
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: MCP server that gives AI agents pre-approved Python, shell, and file I/O tools with declarative policy controls
|
|
5
5
|
Project-URL: Homepage, https://github.com/portablestew/pyddock
|
|
6
6
|
Project-URL: Repository, https://github.com/portablestew/pyddock
|
|
@@ -36,33 +36,39 @@ del _os_for_path
|
|
|
36
36
|
_ORIGINALS: dict[str, Any] = {}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def
|
|
40
|
-
"""
|
|
39
|
+
def ntfs_stream_base(path: Any) -> str | None:
|
|
40
|
+
"""Return the base path of an NTFS alternate-data-stream (ADS) reference.
|
|
41
41
|
|
|
42
42
|
On Windows, ``name:stream`` (and ``name::$DATA``, ``dir:stream``) addresses a
|
|
43
43
|
*different* securable object than the path's lexical components imply: a write
|
|
44
44
|
to ``.pyddock:pwned`` lands a data stream on the ``.pyddock`` directory, yet
|
|
45
45
|
the lexical leaf ``.pyddock:pwned`` is not a child of ``.pyddock`` — so a
|
|
46
46
|
``relative_to('.pyddock')`` containment check decides "not protected" and the
|
|
47
|
-
write slips through.
|
|
48
|
-
(a not-yet-existing stream resolves to the literal), so the only sound defense
|
|
49
|
-
is to reject the syntax up front.
|
|
47
|
+
write slips through.
|
|
50
48
|
|
|
51
49
|
A ``:`` is only legal as the drive designator at index 1 of the FIRST path
|
|
52
50
|
component (``C:\\...`` or the drive-relative ``C:rest``). A ``:`` anywhere else
|
|
53
|
-
|
|
51
|
+
opens a named stream on the component to its left. When such a reference is
|
|
52
|
+
present this returns the lexical BASE — everything up to (but not including)
|
|
53
|
+
the stream ``:`` — i.e. the object the stream would attach to. Returns None
|
|
54
|
+
when no stream reference is present, and on non-Windows, where ``:`` is an
|
|
54
55
|
ordinary, legal filename character.
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
Callers existence-check the resolved base to decide whether the reference is
|
|
58
|
+
security-relevant: the ADS containment-evasion attack aliases a stream onto
|
|
59
|
+
an *existing* (and typically protected) object — ``.pyddock``, a workspace
|
|
60
|
+
module dir, the stdlib — all of which always exist on disk. A colon in a
|
|
61
|
+
string that merely looks path-like (e.g. a commit message) has a base that
|
|
62
|
+
does not exist, so it is not a real stream reference.
|
|
63
|
+
|
|
64
|
+
NOTE: this is purely lexical and makes NO exception for URL-looking strings
|
|
65
|
+
(``https://...``); a ``scheme:`` prefix still carries a stream-bearing ``:``.
|
|
66
|
+
The one place a URL is a legitimate value — a shell CLI argument — filters
|
|
67
|
+
URLs out *before* they reach this check (see ``_looks_like_path`` in
|
|
68
|
+
shell_executor), so URLs never get here in the first place.
|
|
63
69
|
"""
|
|
64
70
|
if _os_name != "nt":
|
|
65
|
-
return
|
|
71
|
+
return None
|
|
66
72
|
parts = str(path).replace("/", "\\").split("\\")
|
|
67
73
|
for idx, comp in enumerate(parts):
|
|
68
74
|
if not comp:
|
|
@@ -71,9 +77,22 @@ def has_ntfs_stream(path: Any) -> bool:
|
|
|
71
77
|
# First component may carry a 'X:' drive designator (X: or X:rest).
|
|
72
78
|
if idx == 0 and len(comp) >= 2 and comp[0].isalpha() and comp[1] == ":":
|
|
73
79
|
start = 2
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
ci = comp.find(":", start)
|
|
81
|
+
if ci != -1:
|
|
82
|
+
base_parts = parts[:idx] + [comp[:ci]]
|
|
83
|
+
return "\\".join(base_parts)
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def has_ntfs_stream(path: Any) -> bool:
|
|
88
|
+
"""Pure-syntactic NTFS ADS detector — True if *path* carries a stream ``:``.
|
|
89
|
+
|
|
90
|
+
See ``ntfs_stream_base`` for the parsing rules. This is the lexical primitive
|
|
91
|
+
(existence-agnostic). Enforcement layers DO NOT call this directly: they
|
|
92
|
+
existence-gate via ``ntfs_stream_base`` so a colon in a non-path string does
|
|
93
|
+
not raise a false positive. Returns False on non-Windows.
|
|
94
|
+
"""
|
|
95
|
+
return ntfs_stream_base(path) is not None
|
|
77
96
|
|
|
78
97
|
|
|
79
98
|
def canonical_path(path: Any) -> pathlib.Path:
|
|
@@ -14,7 +14,7 @@ import tempfile as _tempfile_module
|
|
|
14
14
|
import _io as _cio_module
|
|
15
15
|
from typing import Any
|
|
16
16
|
|
|
17
|
-
from pyddock._base import _ORIGINALS, _PYDDOCK_DIR, _find_deny_hint, canonical_path,
|
|
17
|
+
from pyddock._base import _ORIGINALS, _PYDDOCK_DIR, _find_deny_hint, canonical_path, ntfs_stream_base
|
|
18
18
|
from pyddock._import_hook import _caller_is_trusted
|
|
19
19
|
from pyddock._audit_enforcement import install_audit_enforcement
|
|
20
20
|
from pyddock._process_utils import make_child_env
|
|
@@ -54,16 +54,30 @@ def apply_filesystem_scoping(
|
|
|
54
54
|
"""
|
|
55
55
|
return canonical_path(p)
|
|
56
56
|
|
|
57
|
+
def _resolve_scope_path(p: str) -> pathlib.Path:
|
|
58
|
+
"""Resolve a scope path entry to an absolute, canonicalized path.
|
|
59
|
+
|
|
60
|
+
Supports:
|
|
61
|
+
- "~" or "~/..." — expanded via os.path.expanduser
|
|
62
|
+
- Absolute paths (e.g. "C:\\Users\\...") — used as-is
|
|
63
|
+
- Relative paths (e.g. ".", "src") — joined with workspace_root
|
|
64
|
+
"""
|
|
65
|
+
expanded = _real_os.path.expanduser(p)
|
|
66
|
+
path = pathlib.Path(expanded)
|
|
67
|
+
if path.is_absolute():
|
|
68
|
+
return _abspath(path)
|
|
69
|
+
return _abspath(workspace_root / expanded)
|
|
70
|
+
|
|
57
71
|
# Canonicalize allowed paths (realpath: resolves symlinks/junctions/8.3
|
|
58
72
|
# names) so they compare consistently with canonicalized candidate paths.
|
|
59
73
|
resolved_writable = [
|
|
60
|
-
|
|
74
|
+
_resolve_scope_path(p) for p in writable_paths
|
|
61
75
|
]
|
|
62
76
|
|
|
63
77
|
# "*" means unrestricted reads
|
|
64
78
|
unrestricted_reads = "*" in readable_paths
|
|
65
79
|
resolved_readable = [
|
|
66
|
-
|
|
80
|
+
_resolve_scope_path(p) for p in readable_paths if p != "*"
|
|
67
81
|
]
|
|
68
82
|
|
|
69
83
|
# .pyddock/ is always excluded from writes (self-modification protection)
|
|
@@ -243,7 +257,12 @@ def apply_filesystem_scoping(
|
|
|
243
257
|
path = _real_os.fsdecode(path)
|
|
244
258
|
if _is_null_device(path):
|
|
245
259
|
return
|
|
246
|
-
|
|
260
|
+
# NTFS alternate data stream whose base object EXISTS — aliasing a
|
|
261
|
+
# stream onto an existing (often protected) object evades containment
|
|
262
|
+
# checks. Gated on existence to avoid false positives on colon-bearing
|
|
263
|
+
# strings whose base does not exist.
|
|
264
|
+
_stream_base = ntfs_stream_base(path)
|
|
265
|
+
if _stream_base is not None and _real_os.path.exists(_stream_base):
|
|
247
266
|
raise PermissionError(
|
|
248
267
|
f"PermissionError: Cannot read '{path}' — NTFS alternate data "
|
|
249
268
|
f"streams (':' in a path component) are not permitted. Use a "
|
|
@@ -271,7 +290,11 @@ def apply_filesystem_scoping(
|
|
|
271
290
|
path = _real_os.fsdecode(path)
|
|
272
291
|
if _is_null_device(path):
|
|
273
292
|
return
|
|
274
|
-
|
|
293
|
+
# NTFS alternate data stream whose base object EXISTS (see _check_read).
|
|
294
|
+
# The base of '.pyddock:x' is '.pyddock' (always present) — caught; a
|
|
295
|
+
# colon in a non-existent-base string is not a real stream reference.
|
|
296
|
+
_stream_base = ntfs_stream_base(path)
|
|
297
|
+
if _stream_base is not None and _real_os.path.exists(_stream_base):
|
|
275
298
|
raise PermissionError(
|
|
276
299
|
f"PermissionError: Cannot write to '{path}' — NTFS alternate "
|
|
277
300
|
f"data streams (':' in a path component) are not permitted. A "
|
|
@@ -69,7 +69,9 @@ P4 = "p4python" # Restricted to non-submit operations
|
|
|
69
69
|
# Filesystem scoping for run_python.
|
|
70
70
|
# Paths are relative to the workspace root (the --workspace directory or CWD).
|
|
71
71
|
# "." = the workspace directory itself (and everything under it)
|
|
72
|
+
# "~" = user home directory (os.path.expanduser); "~/subdir" works too
|
|
72
73
|
# "*" = unrestricted (entire host filesystem)
|
|
74
|
+
# Absolute paths (e.g. "C:\\Data") are also accepted and used as-is.
|
|
73
75
|
# Writes are always denied to .pyddock/ (self-modification protection) and to
|
|
74
76
|
# paths matching shell-executable script patterns (write-then-execute prevention).
|
|
75
77
|
[filesystem]
|
|
@@ -15,7 +15,7 @@ from pathlib import Path
|
|
|
15
15
|
from typing import Any
|
|
16
16
|
|
|
17
17
|
from pyddock.config import PyddockConfig, ShellPolicyConfig, find_deny_hint
|
|
18
|
-
from pyddock._base import canonical_path,
|
|
18
|
+
from pyddock._base import canonical_path, ntfs_stream_base
|
|
19
19
|
from pyddock._process_utils import get_startupinfo, kill_and_drain, make_child_env, truncate_output
|
|
20
20
|
|
|
21
21
|
import shutil
|
|
@@ -501,11 +501,18 @@ def evaluate_arg_paths(
|
|
|
501
501
|
# NTFS alternate data streams alias a different object than their
|
|
502
502
|
# lexical path implies (e.g. "--output=.pyddock:x" writes onto the
|
|
503
503
|
# protected .pyddock dir while evading the relative_to() check).
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
504
|
+
# Gated on existence of the base object: protected targets always
|
|
505
|
+
# exist, so the attack is still caught, while a colon in a value
|
|
506
|
+
# whose base does not exist is not treated as a stream.
|
|
507
|
+
_stream_base = ntfs_stream_base(candidate)
|
|
508
|
+
if _stream_base is not None:
|
|
509
|
+
_base_p = Path(_stream_base)
|
|
510
|
+
_base_abs = _base_p if _base_p.is_absolute() else workspace_root / _base_p
|
|
511
|
+
if _base_abs.exists():
|
|
512
|
+
return (
|
|
513
|
+
f"Argument '{arg}' uses an NTFS alternate data stream "
|
|
514
|
+
f"(':' in a path component), which is not permitted."
|
|
515
|
+
)
|
|
509
516
|
# Resolve relative to workspace root (same as command cwd)
|
|
510
517
|
resolved = _abspath(workspace_root / candidate)
|
|
511
518
|
|
|
@@ -584,11 +591,15 @@ def evaluate_cwd(
|
|
|
584
591
|
return None
|
|
585
592
|
|
|
586
593
|
cwd_str = cwd.decode("utf-8", "surrogateescape") if isinstance(cwd, bytes) else str(cwd)
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
)
|
|
594
|
+
_cwd_stream_base = ntfs_stream_base(cwd_str)
|
|
595
|
+
if _cwd_stream_base is not None:
|
|
596
|
+
_cwd_base_p = Path(_cwd_stream_base)
|
|
597
|
+
_cwd_base_abs = _cwd_base_p if _cwd_base_p.is_absolute() else workspace_root / _cwd_base_p
|
|
598
|
+
if _cwd_base_abs.exists():
|
|
599
|
+
return (
|
|
600
|
+
f"cwd '{cwd_str}' uses an NTFS alternate data stream (':' in a path "
|
|
601
|
+
f"component), which is not permitted."
|
|
602
|
+
)
|
|
592
603
|
ws_root_abs = _abspath(workspace_root)
|
|
593
604
|
pyddock_dir = _abspath(workspace_root / ".pyddock")
|
|
594
605
|
resolved = _abspath(workspace_root / Path(cwd_str))
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
2. NTFS alternate data streams — `open(".pyddock:pwned", "w")` writes a data
|
|
9
9
|
stream onto the protected `.pyddock` directory while the lexical leaf
|
|
10
10
|
`.pyddock:pwned` evades the `relative_to('.pyddock')` containment check.
|
|
11
|
-
Fixed by
|
|
12
|
-
(
|
|
13
|
-
and the shell arg-path /
|
|
11
|
+
Fixed by detecting a `:` stream reference and rejecting it when the stream's
|
|
12
|
+
BASE object exists on disk (ntfs_stream_base + an existence check), wired
|
|
13
|
+
into the shared _check_read/_check_write closures and the shell arg-path /
|
|
14
|
+
cwd scanners. The existence gate is sound because every protected target
|
|
15
|
+
(.pyddock, workspace module dirs, the stdlib) always exists, so the attack is
|
|
16
|
+
still blocked — while a colon in a string that merely looks path-like (e.g. a
|
|
17
|
+
commit message) has a non-existent base and is no longer a false positive.
|
|
14
18
|
"""
|
|
15
19
|
|
|
16
20
|
from __future__ import annotations
|
|
@@ -138,6 +142,18 @@ class TestHasNtfsStream:
|
|
|
138
142
|
]:
|
|
139
143
|
assert has_ntfs_stream(bad) is True, bad
|
|
140
144
|
|
|
145
|
+
@pytest.mark.skipif(sys.platform != "win32", reason="NTFS ADS is Windows-only")
|
|
146
|
+
def test_stream_base_extraction(self) -> None:
|
|
147
|
+
# ntfs_stream_base returns the object the stream attaches to (or None).
|
|
148
|
+
from pyddock._base import ntfs_stream_base
|
|
149
|
+
|
|
150
|
+
assert ntfs_stream_base(".pyddock:pwned") == ".pyddock"
|
|
151
|
+
assert ntfs_stream_base(".pyddock:pwned.txt") == ".pyddock"
|
|
152
|
+
assert ntfs_stream_base("C:/Git/pyddock/.pyddock:pwned") == "C:\\Git\\pyddock\\.pyddock"
|
|
153
|
+
assert ntfs_stream_base("dir/file.txt:s") == "dir\\file.txt"
|
|
154
|
+
assert ntfs_stream_base("file.txt") is None
|
|
155
|
+
assert ntfs_stream_base("C:\\abs\\file") is None
|
|
156
|
+
|
|
141
157
|
@pytest.mark.skipif(sys.platform != "win32", reason="NTFS ADS is Windows-only")
|
|
142
158
|
def test_drive_relative_not_flagged(self) -> None:
|
|
143
159
|
# 'C:rest' (drive-relative) and 'C:\\...' are the only legal colons.
|
|
@@ -199,6 +215,7 @@ class TestUrlArgsNotPathCandidates:
|
|
|
199
215
|
def test_stream_in_flag_value_still_blocked(self, tmp_path: Path) -> None:
|
|
200
216
|
# The URL exclusion must NOT weaken the output-flag stream attack: a
|
|
201
217
|
# value that is a stream-bearing path (not a scheme://) is still scanned.
|
|
218
|
+
(tmp_path / ".pyddock").mkdir() # base object the stream targets
|
|
202
219
|
reason = evaluate_arg_paths(
|
|
203
220
|
["-o=.pyddock:pwned"],
|
|
204
221
|
arg_paths="protected",
|
|
@@ -220,6 +237,9 @@ class TestAdsWriteBlockedEndToEnd:
|
|
|
220
237
|
) -> None:
|
|
221
238
|
"""open('.pyddock:pwned', 'w') must be rejected — it would otherwise
|
|
222
239
|
write a data stream onto the protected .pyddock directory."""
|
|
240
|
+
# The server always creates .pyddock at startup; mirror that here so the
|
|
241
|
+
# stream's base object exists (the existence gate keys off this).
|
|
242
|
+
(workspace / ".pyddock").mkdir(exist_ok=True)
|
|
223
243
|
config = PyddockConfig(
|
|
224
244
|
execution=ExecutionConfig(timeout=30.0),
|
|
225
245
|
imports=ImportsConfig(allowed=["pathlib", "io"]),
|
|
@@ -471,6 +491,7 @@ class TestAdsArgPathScanBlocked:
|
|
|
471
491
|
def test_shell_output_arg_with_stream_rejected(self, tmp_path: Path) -> None:
|
|
472
492
|
"""A shell arg like --output=.pyddock:x must be rejected by the arg
|
|
473
493
|
scanner (same containment gap as the fs guard)."""
|
|
494
|
+
(tmp_path / ".pyddock").mkdir() # base object the stream targets
|
|
474
495
|
reason = evaluate_arg_paths(
|
|
475
496
|
["--output=.pyddock:pwned"],
|
|
476
497
|
arg_paths="workspace",
|
|
@@ -506,3 +527,17 @@ class TestAdsArgPathScanBlocked:
|
|
|
506
527
|
shell_command_patterns=["^git$"],
|
|
507
528
|
)
|
|
508
529
|
assert reason is None
|
|
530
|
+
|
|
531
|
+
def test_stream_value_with_nonexistent_base_allowed(self, tmp_path: Path) -> None:
|
|
532
|
+
"""Existence gate (false-positive fix): a colon-bearing, path-like value
|
|
533
|
+
whose base object does NOT exist is not treated as a stream. This is what
|
|
534
|
+
keeps colons in non-path strings (e.g. a 'feat: ...' commit message that
|
|
535
|
+
happens to contain a '/') from being rejected as ADS references."""
|
|
536
|
+
reason = evaluate_arg_paths(
|
|
537
|
+
["-o=notes:draft/today.txt"],
|
|
538
|
+
arg_paths="workspace",
|
|
539
|
+
workspace_root=tmp_path,
|
|
540
|
+
workspace_module_dirs={},
|
|
541
|
+
shell_command_patterns=[],
|
|
542
|
+
)
|
|
543
|
+
assert reason is None, reason
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|