From bd974e1f4e0cfa2ffa27692fd9c3c71274137758 Mon Sep 17 00:00:00 2001 From: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:49:50 +0800 Subject: [PATCH 1/5] fix(public-boundary): unify local path verdicts across presentation and guards Refs #5136. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> --- .../control_plane/goals/vision_checkpoint.ts | 2 +- loopx/extensions/presentation.py | 11 +-- loopx/public_safe_text.py | 22 ++++++ .../test_public_safe_local_path_owner.py | 1 + .../test_public_safe_text_owner_parity.py | 48 ++++++++++++ ...t_public_safety_credential_caller_faces.py | 17 +++-- .../public_safe_text_corpus.test.ts | 27 +++++++ .../extensions/test_extension_presentation.py | 73 +++++++++++++++++++ tests/fixtures/public_safe_text_corpus.json | 42 +++++++++++ 9 files changed, 229 insertions(+), 14 deletions(-) diff --git a/loopx/control_plane/goals/vision_checkpoint.ts b/loopx/control_plane/goals/vision_checkpoint.ts index 7e75a19d42..405ba135ae 100644 --- a/loopx/control_plane/goals/vision_checkpoint.ts +++ b/loopx/control_plane/goals/vision_checkpoint.ts @@ -199,7 +199,7 @@ const LABELED_CREDENTIAL_ASSIGNMENT = /\b(?:Bearer|token|password|secret)["']?\s // outside the internal-state policy, and the per-face URL decision is the // caller-migration work still open in #5136. const SECRET_LIKE_SHAPE = new RegExp("(?:\\bbearer\\s+[a-z0-9._~+/=-]{16,}|\\b[a-z][a-z0-9+.-]*://[^/\\s:@`'\\\"<>]+:[^/\\s@`'\\\"<>]+@[^\\s`'\\\"<>]*|\\b(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|(?:access|api|secret)[_-]?key)[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]+|\\b(?:ak|sk)[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]+|(?]{12,}|\\b(?:password|secret)[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]{12,}|-{3,}\\s*BEGIN (?:[A-Z]+ )?PRIVATE KEY[\\s\\S]*?(?:-{3,}\\s*END (?:[A-Z]+ )?PRIVATE KEY-{3,}|$)|\\btoken[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]{12,})", "i"); -const LOCAL_PATH_SHAPE = new RegExp("(?]+|[A-Za-z]:[\\\\/][^\\s`'\\\"<>]+|\\\\\\\\[A-Za-z0-9_.-]+\\\\[^\\s`'\\\"<>]+)", "i"); +const LOCAL_PATH_SHAPE = new RegExp("(?]+|[A-Za-z]:[\\\\/][^\\s`'\\\"<>]+|\\\\\\\\[A-Za-z0-9_.-]+\\\\[^\\s`'\\\"<>]+)", "i"); export const CREDENTIAL_WORD_PATTERNS: RegExp[] = [/\bBearer\b/i, /\bpassword\b/i, /\bsecret\b/i]; export const PRIVATE_TEXT_PATTERNS: RegExp[] = [ /\/Users\//, diff --git a/loopx/extensions/presentation.py b/loopx/extensions/presentation.py index 2980c18759..0e9f651c23 100644 --- a/loopx/extensions/presentation.py +++ b/loopx/extensions/presentation.py @@ -50,10 +50,11 @@ _ANCHOR_RE = re.compile(r"^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$") _MARKUP_RE = re.compile(r"<[^>]*>|javascript:", re.IGNORECASE) -_LOCAL_PATH_RE = re.compile( - r"(?:^|[\s(])(?:~[/\\]|/+(?:Users|home|tmp|private|var|etc|opt)/|" - r"[A-Za-z]:[\\/])" -) +# Absolute, home-relative, drive/UNC, file:// and path:-prefixed local references +# are decided once by the shared owner. This module keeps one separate policy: +# a reference to a private *relative* directory (`.codex`, `.git`, `.local`) is +# not an absolute-root shape, and presenting a project-local private directory is +# still forbidden here. _PRIVATE_RELATIVE_PATH_RE = re.compile( r"(?:^|[\s:=('/\\])\.(?:codex|git|local)(?:[/\\]|$)", re.IGNORECASE, @@ -165,7 +166,7 @@ def _plain_text( raise ValueError(f"{context} must contain at most {max_length} characters") if "\x00" in text or _MARKUP_RE.search(text): raise ValueError(f"{context} must be plain text without markup") - if _LOCAL_PATH_RE.search(text) or _PRIVATE_RELATIVE_PATH_RE.search(text): + if find_public_safe_local_path(text) or _PRIVATE_RELATIVE_PATH_RE.search(text): raise ValueError(f"{context} must not contain a local path") if SECRET_LIKE_SURFACE_PATTERN.search(text) or _CREDENTIAL_RE.search(text): raise ValueError(f"{context} must not contain credential material") diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index e2c5c6c928..495a609cf3 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -236,6 +236,19 @@ r")", re.IGNORECASE, ) + +# Refs #5136, direction 3: a run of two or more leading slashes before a known +# absolute root is the shape presentation and the public-output guards already +# treat as a local reference. `LOCAL_PATH_SURFACE_PATTERN`'s negative lookbehind +# excludes a preceding slash, so that shape needs this named arm. The lookbehind +# also keeps a URI such as `https://Users/...` out: the character before the run +# is `:`. +MULTI_SLASH_LOCAL_PATH_PATTERN = re.compile( + r"(?]+", + re.IGNORECASE, +) # Refs #5136, direction 3: the local-path shapes this owner recognizes. # `LOCAL_PATH_SURFACE_PATTERN` carries the absolute roots, Windows drive letters # and UNC shares; the gap pair adds the home-relative `~/...` form and a local @@ -265,6 +278,7 @@ FILE_URL_LOCAL_PATH_PATTERN = re.compile(r"\bfile://", re.IGNORECASE) PUBLIC_SAFE_LOCAL_PATH_PATTERNS: tuple[re.Pattern[str], ...] = ( LOCAL_PATH_SURFACE_PATTERN, + MULTI_SLASH_LOCAL_PATH_PATTERN, HOME_RELATIVE_PATH_PATTERN, PATH_PREFIX_LOCAL_PATTERN, LOCAL_PATH_BOUNDARY_REFERENCE_PATTERN, @@ -293,6 +307,7 @@ PRESENTATION_LOCAL_PATH_PATTERNS: tuple[re.Pattern[str], ...] = ( re.compile(r"/(?:Users|home|private|tmp|var)/[^\s`|,)]+"), LOCAL_PATH_SURFACE_PATTERN, + MULTI_SLASH_LOCAL_PATH_PATTERN, PRESENTATION_EXTENDED_WINDOWS_PATH_PATTERN, PRESENTATION_COLON_PREFIXED_WINDOWS_PATH_PATTERN, ) @@ -330,6 +345,8 @@ + "|" + PRESENTATION_EXTENDED_WINDOWS_PATH_PATTERN.pattern + ")|" + + MULTI_SLASH_LOCAL_PATH_PATTERN.pattern + + "|" + PRESENTATION_COLON_PREFIXED_WINDOWS_PATH_PATTERN.pattern ), ), @@ -577,6 +594,11 @@ def find_private_text_match(value: str | None) -> re.Pattern[str] | None: _SHAPE_DETECTORS: tuple[tuple[re.Pattern[str], str, str], ...] = ( (SECRET_LIKE_SURFACE_PATTERN, CATEGORY_CREDENTIAL, "credential-like value shape"), (LOCAL_PATH_SURFACE_PATTERN, CATEGORY_LOCAL_PATH, "local filesystem path"), + # #5136 direction 3: the 2+ leading-slash shape presentation and the + # public-output guards already rejected. It stays a shape detector, so + # `find_private_text_match` keeps its narrower publication-tier set while + # `classify_private_text` and the public-output guard recognize it. + (MULTI_SLASH_LOCAL_PATH_PATTERN, CATEGORY_LOCAL_PATH, "local filesystem path"), ( REMOTE_LOCATION_SURFACE_PATTERN, CATEGORY_REMOTE_LOCATION, diff --git a/tests/control_plane/test_public_safe_local_path_owner.py b/tests/control_plane/test_public_safe_local_path_owner.py index 2cbfe5f1e7..763e0615fb 100644 --- a/tests/control_plane/test_public_safe_local_path_owner.py +++ b/tests/control_plane/test_public_safe_local_path_owner.py @@ -134,6 +134,7 @@ def test_neither_site_declares_a_local_path_regex_any_more() -> None: def test_owner_recognizes_the_absolute_roots_the_gaps_and_the_boundary_form() -> None: assert owner.PUBLIC_SAFE_LOCAL_PATH_PATTERNS == ( owner.LOCAL_PATH_SURFACE_PATTERN, + owner.MULTI_SLASH_LOCAL_PATH_PATTERN, owner.HOME_RELATIVE_PATH_PATTERN, owner.PATH_PREFIX_LOCAL_PATTERN, owner.LOCAL_PATH_BOUNDARY_REFERENCE_PATTERN, diff --git a/tests/control_plane/test_public_safe_text_owner_parity.py b/tests/control_plane/test_public_safe_text_owner_parity.py index 0aeb81945a..8f7879b4ca 100644 --- a/tests/control_plane/test_public_safe_text_owner_parity.py +++ b/tests/control_plane/test_public_safe_text_owner_parity.py @@ -27,12 +27,14 @@ from loopx.boundary_authority import build_checkpointed_boundary_authority_entry from loopx.control_plane.goals.vision_checkpoint import build_vision_checkpoint from loopx.feedback import validate_public_safe_text as validate_feedback_text +from loopx.control_plane.runtime.public_safety import validate_public_safe_value from loopx.public_safe_text import ( ALL_CATEGORIES, CATEGORY_CREDENTIAL_WORD, TEXT_OWNER_CATEGORIES, classify_private_text, find_private_text_match, + find_public_safe_local_path, ) CORPUS_PATH = ( @@ -71,6 +73,7 @@ def _samples(group: str) -> list[tuple[str, str]]: PUBLIC_SAFE_SAMPLES = _samples("public_safe") PRIVATE_LOOKING_SAMPLES = _samples("private_looking") INTERNAL_STATE_PROSE_SAMPLES = _samples("internal_state_prose") +LOCAL_PATH_SHAPES = _load_corpus()["local_path_shapes"] def _shaped_samples(group: str) -> list[tuple[str, str, str]]: @@ -110,6 +113,31 @@ def _ids(samples: list[tuple[str, str]]) -> list[str]: return [sample_id for sample_id, _ in samples] +@pytest.mark.parametrize( + "sample", + LOCAL_PATH_SHAPES, + ids=[str(sample["id"]) for sample in LOCAL_PATH_SHAPES], +) +def test_local_path_shapes_are_pinned_in_both_directions( + sample: dict[str, Any], +) -> None: + # The corpus is the contract, so the table in #5136 is pinned here rather + # than rediscovered by a reviewer. The text-owner publication helper keeps + # its narrower boundary-assignment verdict; the public-output guard is the + # destination that must reject every row. + value = str(sample["value"]) + assert bool(find_public_safe_local_path(value)) is sample["public_safe_local_path"] + assert bool(find_private_text_match(value)) is sample["publication_tier_path"] + assert bool(classify_private_text(value)) is sample["classify_path"] + with pytest.raises(ValueError, match="local path"): + validate_public_safe_value({"value": value}) + + +def test_public_output_guard_keeps_remote_urls_and_ordinary_prose() -> None: + for value in ("https://example.com/docs", "the token budget is 1200"): + validate_public_safe_value({"value": value}) + + def _boundary_authority_text(text: str) -> None: """Drive boundary_authority through its public builder, not its helper.""" @@ -140,6 +168,26 @@ def _vision_text(text: str) -> None: ) OWNER_IDS = [owner_id for owner_id, _ in OWNERS] +@pytest.mark.parametrize( + "owner", [check for _, check in OWNERS[:3]], ids=OWNER_IDS[:3] +) +@pytest.mark.parametrize( + "sample", + LOCAL_PATH_SHAPES, + ids=[str(sample["id"]) for sample in LOCAL_PATH_SHAPES], +) +def test_local_path_shapes_are_rejected_by_the_python_text_owners( + owner: Any, + sample: dict[str, Any], +) -> None: + # The acceptance asks for a named subset, not an argument. These three + # Python owners all publish LoopX state, and every row is a local reference + # their destination must not carry. + with pytest.raises(ValueError, match="private-looking value"): + owner(str(sample["value"])) + + + EXTENDED_WINDOWS_PATHS = ( r"\\?\UNC\fileserver\share\a.md", r"\\?\Volume{01234567-89ab-cdef-0123-456789abcdef}\notes\a.md", diff --git a/tests/control_plane/test_public_safety_credential_caller_faces.py b/tests/control_plane/test_public_safety_credential_caller_faces.py index a057f74b79..96dde8e0c7 100644 --- a/tests/control_plane/test_public_safety_credential_caller_faces.py +++ b/tests/control_plane/test_public_safety_credential_caller_faces.py @@ -256,14 +256,15 @@ def test_the_named_policy_lists_both_credential_categories() -> None: # verdict: direction 2 asks for an explicit, tested short-assignment policy and # does not say which way, so this face stays where it is until that is decided. "loopx/extensions/presentation.py": "short-assignment verdict undecided", - # The public-boundary contract is the publication tier: it refuses a label with - # no value at all -- a trailing scheme word, an assignment operator with an - # empty right side -- which is exactly what the owner's publication helper - # `find_private_text_match` already answers. Moving it is one call with the - # publication categories, but it decides the tier for every surface that passes - # the contract, so it needs the corpus parity evidence behind it rather than two - # capability faces' tables. - "loopx/contract.py": "publication tier, needs its own corpus parity slice", + # The public-boundary contract answers a different question: is a credential + # being written into code or logs? Its `CREDENTIAL_ENVIRONMENT_REFERENCE_PATTERN`, + # `CREDENTIAL_HIGH_ENTROPY_VALUE_PATTERN` and + # `CREDENTIAL_VARIABLE_REFERENCE_PATTERN` classes are not publication-tier + # text shapes, so moving it onto `find_private_text_match` would drop those + # three detections. The corpus parity prerequisite once claimed here already + # exists; the reason for keeping the site is its distinct decision, not a + # missing slice. + "loopx/contract.py": "code-time credential question, not the publication tier", } diff --git a/tests/control_plane_ts/public_safe_text_corpus.test.ts b/tests/control_plane_ts/public_safe_text_corpus.test.ts index 6866ab761c..5183643992 100644 --- a/tests/control_plane_ts/public_safe_text_corpus.test.ts +++ b/tests/control_plane_ts/public_safe_text_corpus.test.ts @@ -30,6 +30,14 @@ interface CorpusSample { note?: string; } +interface LocalPathShape { + id: string; + value: string; + public_safe_local_path: boolean; + publication_tier_path: boolean; + classify_path: boolean; +} + interface Corpus { schema_version: string; contract_signals: Record; @@ -37,6 +45,7 @@ interface Corpus { public_safe: CorpusSample[]; private_looking: CorpusSample[]; internal_state_prose: CorpusSample[]; + local_path_shapes: LocalPathShape[]; } const corpus = JSON.parse(readFileSync(CORPUS_PATH, "utf8")) as Corpus; @@ -97,6 +106,24 @@ test("vision checkpoint accepts the internal-state prose corpus", () => { } }); +test("local path shapes keep the internal tier and publication tier aligned", () => { + // Python's owner-parity test drives the same rows through + // find_public_safe_local_path, find_private_text_match and + // classify_private_text. Here the two TypeScript pattern sets are pinned to + // the same expected verdicts, including the deliberate difference on the + // boundary-assignment and 2+ leading-slash forms. + for (const sample of corpus.local_path_shapes) { + const internal = INTERNAL_STATE_PRIVATE_TEXT_PATTERNS.some((pattern) => + pattern.test(sample.value), + ); + const publication = PRIVATE_TEXT_PATTERNS.some((pattern) => + pattern.test(sample.value), + ); + assert.equal(internal, sample.classify_path, sample.id); + assert.equal(publication, sample.publication_tier_path, sample.id); + } +}); + test("the internal-state tier drops the words and adds the ported shapes", () => { // Without this, dropping a word arm and dropping a value arm would look the // same from the corpus alone. The composition is pinned, not the count. diff --git a/tests/extensions/test_extension_presentation.py b/tests/extensions/test_extension_presentation.py index 98fcd30ecc..1fd65f3356 100644 --- a/tests/extensions/test_extension_presentation.py +++ b/tests/extensions/test_extension_presentation.py @@ -16,6 +16,7 @@ default_extension_projection_root, publish_extension_projection, read_extension_projection, + validate_opaque_presentation_view, ) from loopx.extensions.runtime import ( disable_extension, @@ -827,3 +828,75 @@ def test_publish_projection_dry_run_does_not_load_validator( assert not default_extension_projection_root(state_file).exists(), ( "dry-run must not write projection" ) + + +LOCAL_PATH_VIEW_VALUES = ( + "see file:///Users/alice/goal.md", + "path:/Users/alice/goal.md", + "///tmp/a.log", + "//Users/alex/x", + "x=/private/a", +) + + +@pytest.mark.parametrize("value", LOCAL_PATH_VIEW_VALUES) +def test_opaque_view_rejects_every_local_path_shape(value: str) -> None: + # The migration must not loosen presentation's historical reject side. Each + # row was either accepted here before the migration (the first three) or + # rejected by the old local regex (the last two); all five now come from the + # shared owner. + with pytest.raises(ValueError, match="must not contain a local path"): + validate_opaque_presentation_view({"headline": value}) + + +def test_opaque_view_keeps_ordinary_remote_urls_and_prose() -> None: + view = { + "headline": "https://example.com/docs", + "body": "the token budget is 1200", + } + assert validate_opaque_presentation_view(view) == view + + +@pytest.mark.skipif(os.name == "nt", reason="POSIX console-script shebang fixture") +def test_projection_publication_rejects_local_path_without_rewriting( + tmp_path: Path, +) -> None: + state_file, _ = _installed_projection_extension(tmp_path) + first = publish_extension_projection( + "test-research-extension", + "investment-research", + state_file=state_file, + request={"schema_version": "synthetic_request_v0"}, + execute=True, + ) + projection_file = ( + default_extension_projection_root(state_file) + / "test-research-extension" + / "investment-research.json" + ) + previous_bytes = projection_file.read_bytes() + + invalid = _provider_projection() + projection = invalid["presentation_projection"] + assert isinstance(projection, dict) + view = projection["view"] + assert isinstance(view, dict) + view["headline"] = "see file:///Users/alice/goal.md" + _projection_provider(tmp_path / "provider", projection=invalid) + doctor_installed_extension( + "test-research-extension", + state_file=state_file, + execute=True, + ) + + with pytest.raises(ValueError, match="must not contain a local path"): + publish_extension_projection( + "test-research-extension", + "investment-research", + state_file=state_file, + request={"schema_version": "synthetic_request_v0"}, + execute=True, + ) + + assert projection_file.read_bytes() == previous_bytes + assert json.loads(previous_bytes)["payload_sha256"] == first["payload_sha256"] diff --git a/tests/fixtures/public_safe_text_corpus.json b/tests/fixtures/public_safe_text_corpus.json index becfb4880d..7ad23b88a1 100644 --- a/tests/fixtures/public_safe_text_corpus.json +++ b/tests/fixtures/public_safe_text_corpus.json @@ -370,5 +370,47 @@ "shape": "credential_word_only", "note": "The contract's stated limit, pinned rather than argued: a letter-only run of fifteen characters or fewer beside the label, with no quotes and no assignment punctuation, is prose to this owner. The publication tier still rejects the mention, and the tier documents itself as not a credential-storage exemption. Fifteen letters is one below the ceiling." } + ], + "local_path_shapes": [ + { + "id": "file_url_home", + "value": "see file:///Users/alice/goal.md", + "public_safe_local_path": true, + "publication_tier_path": true, + "classify_path": true, + "note": "Presentation accepted this before the migration; the shared owner and the public-output guard already rejected it." + }, + { + "id": "path_prefixed_home", + "value": "path:/Users/alice/goal.md", + "public_safe_local_path": true, + "publication_tier_path": true, + "classify_path": true, + "note": "The direction-3 prefixed form; presentation accepted it before the migration." + }, + { + "id": "slash_run_tmp", + "value": "///tmp/a.log", + "public_safe_local_path": true, + "publication_tier_path": false, + "classify_path": true, + "note": "Presentation rejected this before the migration while the owner did not recognize it; the shared multi-slash arm closes that gap." + }, + { + "id": "slash_run_home", + "value": "//Users/alex/x", + "public_safe_local_path": true, + "publication_tier_path": true, + "classify_path": true, + "note": "The publication tier already recognized /Users/ inside the run; the local-path owner did not." + }, + { + "id": "boundary_assignment_private", + "value": "x=/private/a", + "public_safe_local_path": true, + "publication_tier_path": false, + "classify_path": true, + "note": "The text-owner publication helper does not carry the boundary-assignment shape; the public-output guard and presentation do, and classify_private_text names it." + } ] } From b59102d0718952481b92c81fb8a4bc070ab1cafd Mon Sep 17 00:00:00 2001 From: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:07:34 +0800 Subject: [PATCH 2/5] test(steward): remove unused pytest import Refs #5136; unblocks the repository-wide lint lane used by this PR. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> --- tests/test_steward_generic_monitor_todo.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_steward_generic_monitor_todo.py b/tests/test_steward_generic_monitor_todo.py index c5dea880c1..22d661b67a 100644 --- a/tests/test_steward_generic_monitor_todo.py +++ b/tests/test_steward_generic_monitor_todo.py @@ -4,8 +4,6 @@ from datetime import datetime, timedelta, timezone import json from pathlib import Path -import pytest - from loopx.capabilities.native_chat.steward_monitor import ( StewardMonitor, pump_steward_monitors, From a24325ac2655197a72c88c754d414f4ca7ed3947 Mon Sep 17 00:00:00 2001 From: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:26:46 +0800 Subject: [PATCH 3/5] fix(public-boundary): preserve directory roots and HTTP URL paths Refs #5136. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> --- .../control_plane/goals/vision_checkpoint.ts | 8 +- .../presentation/global_risk_read.ts | 3 +- loopx/control_plane/runtime/public_safety.py | 12 +- loopx/public_safe_text.py | 44 ++++++-- .../test_public_safe_local_path_owner.py | 26 +++++ .../test_public_safe_text_owner_parity.py | 12 ++ .../test_public_safety_text_budget.py | 5 + .../extensions/test_extension_presentation.py | 104 ++++++++++++++++++ 8 files changed, 197 insertions(+), 17 deletions(-) diff --git a/loopx/control_plane/goals/vision_checkpoint.ts b/loopx/control_plane/goals/vision_checkpoint.ts index 405ba135ae..7f900b8f53 100644 --- a/loopx/control_plane/goals/vision_checkpoint.ts +++ b/loopx/control_plane/goals/vision_checkpoint.ts @@ -199,7 +199,10 @@ const LABELED_CREDENTIAL_ASSIGNMENT = /\b(?:Bearer|token|password|secret)["']?\s // outside the internal-state policy, and the per-face URL decision is the // caller-migration work still open in #5136. const SECRET_LIKE_SHAPE = new RegExp("(?:\\bbearer\\s+[a-z0-9._~+/=-]{16,}|\\b[a-z][a-z0-9+.-]*://[^/\\s:@`'\\\"<>]+:[^/\\s@`'\\\"<>]+@[^\\s`'\\\"<>]*|\\b(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|(?:access|api|secret)[_-]?key)[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]+|\\b(?:ak|sk)[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]+|(?]{12,}|\\b(?:password|secret)[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]{12,}|-{3,}\\s*BEGIN (?:[A-Z]+ )?PRIVATE KEY[\\s\\S]*?(?:-{3,}\\s*END (?:[A-Z]+ )?PRIVATE KEY-{3,}|$)|\\btoken[\\\"']?\\s*[=:]\\s*[\\\"']?[^\\s`'\\\"<>]{12,})", "i"); -const LOCAL_PATH_SHAPE = new RegExp("(?]+|[A-Za-z]:[\\\\/][^\\s`'\\\"<>]+|\\\\\\\\[A-Za-z0-9_.-]+\\\\[^\\s`'\\\"<>]+)", "i"); +const LOCAL_PATH_SHAPE = new RegExp("(?]+)?|[A-Za-z]:[\\\\/](?:[^\\s`'\\\"<>]+)?|\\\\\\\\[A-Za-z0-9_.-]+\\\\[^\\s`'\\\"<>]+)", "i"); +const HTTP_URL_SURFACE = /\bhttps?:\/\/[^\s`'"<>]+/giu; +const maskHttpUrlPaths = (value: string): string => + value.replace(HTTP_URL_SURFACE, match => " ".repeat(match.length)); export const CREDENTIAL_WORD_PATTERNS: RegExp[] = [/\bBearer\b/i, /\bpassword\b/i, /\bsecret\b/i]; export const PRIVATE_TEXT_PATTERNS: RegExp[] = [ /\/Users\//, @@ -359,7 +362,8 @@ function publicSafeTextGuidance(label: string): string { function validatePublicSafeText(label: string, value: string): void { for (const pattern of INTERNAL_STATE_PRIVATE_TEXT_PATTERNS) { - if (pattern.test(value)) { + const candidate = pattern === LOCAL_PATH_SHAPE ? maskHttpUrlPaths(value) : value; + if (pattern.test(candidate)) { throw new EffectRuntimeRequestError( `${label} contains a private-looking value; ${publicSafeTextGuidance(label)}`, ); diff --git a/loopx/control_plane/presentation/global_risk_read.ts b/loopx/control_plane/presentation/global_risk_read.ts index e6960758b4..b4806ea23f 100644 --- a/loopx/control_plane/presentation/global_risk_read.ts +++ b/loopx/control_plane/presentation/global_risk_read.ts @@ -31,7 +31,8 @@ const text = (value: unknown): string => stripPythonWhitespace(pyString(truth(va // Mirrors loopx/public_safe_text.py PRESENTATION_LOCAL_PATH_PATTERNS; guarded by parity test. export const LOCAL_PATH_PATTERNS = [ /\/(?:Users|home|private|tmp|var)\/[^\s`|,)]+/gu, - /(?]+|[A-Za-z]:[\\/][^\s`'"<>]+|\\\\[A-Za-z0-9_.-]+\\[^\s`'"<>]+)/giu, + /(?]+)?|[A-Za-z]:[\\/](?:[^\s`'"<>]+)?|\\\\[A-Za-z0-9_.-]+\\[^\s`'"<>]+)/giu, + /(?]+)?/giu, /\\\\\?\\(?:UNC\\[A-Za-z0-9_.-]+\\|Volume\{[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}\}\\|GLOBALROOT\\Device\\)[^\s`|,)]+/giu, /(?<=:)(?:[A-Za-z]:[\\/][^\s`|,)]+|\\\\\?\\(?:UNC\\[A-Za-z0-9_.-]+\\|Volume\{[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}\}\\)[^\s`|,)]+|\\\\\?\\GLOBALROOT\\Device\\[^\s`|,)]+|\\\\[A-Za-z0-9_.-]+\\[^\s`|,)]+)/giu, ]; diff --git a/loopx/control_plane/runtime/public_safety.py b/loopx/control_plane/runtime/public_safety.py index 68ecdd44ec..45edb1c11a 100644 --- a/loopx/control_plane/runtime/public_safety.py +++ b/loopx/control_plane/runtime/public_safety.py @@ -17,6 +17,7 @@ REMOTE_LOCATION_SURFACE_PATTERN as REMOTE_LOCATION_SURFACE_PATTERN, SECRET_LIKE_SURFACE_PATTERN as SECRET_LIKE_SURFACE_PATTERN, find_public_safe_local_path as find_public_safe_local_path, + mask_http_url_paths as mask_http_url_paths, ) NormalizeText = Callable[..., str] @@ -145,9 +146,14 @@ def public_safe_compact_text( text = normalize(str(value or ""), limit=limit) if not text: return None - if local_path_surface_pattern.search(text) or secret_like_surface_pattern.search( - text - ): + local_path_text = ( + mask_http_url_paths(text) + if local_path_surface_pattern is LOCAL_PATH_SURFACE_PATTERN + else text + ) + if local_path_surface_pattern.search( + local_path_text + ) or secret_like_surface_pattern.search(text): return None return text diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 495a609cf3..092f97f761 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -223,15 +223,15 @@ # Refs #5136: relocated here from control_plane/runtime/public_safety.py so a # single owner defines each shape. public_safety re-exports these names, so its -# ~8 direct importers and 30+ recursive-validation callers are unchanged. This -# pattern is byte-identical to the one public_safety enforced before the move: -# slice A is a behavior-preserving consolidation, so no existing consumer's -# verdict changes. +# ~8 direct importers and 30+ recursive-validation callers are unchanged. The +# absolute-root arm keeps the whole path when one follows; the optional tail +# preserves presentation's older rejection of a directory root such as +# `/Users/` or `C:\\`. LOCAL_PATH_SURFACE_PATTERN = re.compile( r"(?]+|" - r"[A-Za-z]:[\\/][^\s`'\"<>]+|" + r"(?:[^\s`'\"<>]+)?|" + r"[A-Za-z]:[\\/](?:[^\s`'\"<>]+)?|" r"\\\\[A-Za-z0-9_.-]+\\[^\s`'\"<>]+" r")", re.IGNORECASE, @@ -246,7 +246,7 @@ MULTI_SLASH_LOCAL_PATH_PATTERN = re.compile( r"(?]+", + r"(?:[^\s`'\"<>]+)?", re.IGNORECASE, ) # Refs #5136, direction 3: the local-path shapes this owner recognizes. @@ -258,7 +258,9 @@ # Typed public exports also reject file URLs, including host-qualified ones. # The internal text-owner classifier and legacy compactor retain their separate # policies; recognizing a locator here does not change those destinations. -HOME_RELATIVE_PATH_PATTERN = re.compile(r"(?]+") +HOME_RELATIVE_PATH_PATTERN = re.compile( + r"(?]+)?" +) PATH_PREFIX_LOCAL_PATTERN = re.compile( r"(?]+", re.IGNORECASE ) @@ -276,6 +278,7 @@ re.IGNORECASE, ) FILE_URL_LOCAL_PATH_PATTERN = re.compile(r"\bfile://", re.IGNORECASE) +HTTP_URL_SURFACE_PATTERN = re.compile(r"\bhttps?://[^\s`'\"<>]+", re.IGNORECASE) PUBLIC_SAFE_LOCAL_PATH_PATTERNS: tuple[re.Pattern[str], ...] = ( LOCAL_PATH_SURFACE_PATTERN, MULTI_SLASH_LOCAL_PATH_PATTERN, @@ -284,6 +287,22 @@ LOCAL_PATH_BOUNDARY_REFERENCE_PATTERN, FILE_URL_LOCAL_PATH_PATTERN, ) + + +def mask_http_url_paths(value: str) -> str: + """Blank ordinary HTTP(S) URLs before applying local-path detectors. + + A public documentation link may legitimately contain a segment such as + ``/home/``, a query value that looks like an absolute path, or an IPv6 + authority. Those are URL syntax, not references to the local filesystem. + Masking preserves character positions for callers that need a regex match, + while leaving ``file://`` and ``path:`` forms visible to their local-path + arms. Credential detection uses the original value. + """ + + return HTTP_URL_SURFACE_PATTERN.sub(lambda match: " " * len(match.group(0)), value) + + # Presentation redaction keeps its historical Unix-root boundary behavior (it # catches paths even after a colon), consumes the shared absolute, drive-letter # and UNC detector, and recognizes extended Windows device paths for display @@ -623,8 +642,9 @@ def find_public_safe_local_path(value: str | None) -> re.Pattern[str] | None: if not value: return None + masked = mask_http_url_paths(value) for pattern in PUBLIC_SAFE_LOCAL_PATH_PATTERNS: - if pattern.search(value): + if pattern.search(masked): return pattern return None @@ -658,15 +678,17 @@ def classify_private_text( if not value: return None + local_path_value = mask_http_url_paths(value) for entry in _CATEGORIZED_PRIVATE_TEXT_PATTERNS: if entry.category in categories and entry.pattern.search(value): return PrivateTextMatch(entry.category, entry.reason, entry.pattern) for pattern, category, reason in _SHAPE_DETECTORS: - if category in categories and pattern.search(value): + candidate = local_path_value if category == CATEGORY_LOCAL_PATH else value + if category in categories and pattern.search(candidate): return PrivateTextMatch(category, reason, pattern) if include_path_gaps and CATEGORY_LOCAL_PATH in categories: for pattern in LOCAL_PATH_GAP_PATTERNS: - if pattern.search(value): + if pattern.search(local_path_value): return PrivateTextMatch( CATEGORY_LOCAL_PATH, "local path behind a relative/prefixed form", pattern ) diff --git a/tests/control_plane/test_public_safe_local_path_owner.py b/tests/control_plane/test_public_safe_local_path_owner.py index 763e0615fb..4001b57d41 100644 --- a/tests/control_plane/test_public_safe_local_path_owner.py +++ b/tests/control_plane/test_public_safe_local_path_owner.py @@ -58,8 +58,10 @@ def _shapes_the_owner_recognizes() -> list[str]: "path:/srv/data/goal.json", "PATH:\\\\fileserver\\share", "/Users/alex/notes.md", + "/home/", "/home/alex/.codex/auth.json", "/var/folders/9x/private/notes", + "///var/", "/private/tmp/x/lease.log", "/tmp/build/out.log", "/etc/loopx/registry.json", @@ -69,6 +71,7 @@ def _shapes_the_owner_recognizes() -> list[str]: "/workspace/private/notes.md", "/data/goal-evidence/dump", "C:\\Users\\alex\\notes.md", + "C:\\", "D:/notes/private.md", "\\\\fileserver\\share\\notes.md", # The boundary form: introduced by a colon or equals sign, which the @@ -158,6 +161,26 @@ def test_owner_never_loosens_what_the_shared_corpus_already_established( assert owner.find_public_safe_local_path(value) is not None +@pytest.mark.parametrize( + "value", + ( + "https://docs.example.test./home/overview", + "https://[2001:db8::1]/home/overview", + "https://docs.example.com/?next=/home/overview", + ), +) +def test_owner_does_not_treat_an_http_url_path_as_a_local_reference( + value: str, +) -> None: + assert owner.find_public_safe_local_path(value) is None + assert owner.mask_http_url_paths(value) != value + + +def test_owner_still_finds_a_local_reference_beside_an_http_url() -> None: + value = "https://docs.example.test./home/overview and /Users/alice/notes.md" + assert owner.find_public_safe_local_path(value) is not None + + def test_owner_covers_the_whole_legacy_equivalence_class() -> None: # Enumerated rather than hand-picked: every boundary character x every root # the copies knew or direction 3 names x a trailing segment. The claim this @@ -222,8 +245,10 @@ def test_the_widening_is_the_direction_three_shapes_not_the_corpus() -> None: "~\\notes.md", "path:/srv/data/goal.json", "PATH:\\\\fileserver\\share", + "/home/", "/home/alex/.codex/auth.json", "/var/folders/9x/private/notes", + "///var/", "/etc/loopx/registry.json", "/opt/secrets/token", "/mnt/nas/private.log", @@ -231,6 +256,7 @@ def test_the_widening_is_the_direction_three_shapes_not_the_corpus() -> None: "/workspace/private/notes.md", "/data/goal-evidence/dump", "C:\\Users\\alex\\notes.md", + "C:\\", "D:/notes/private.md", "\\\\fileserver\\share\\notes.md", ] diff --git a/tests/control_plane/test_public_safe_text_owner_parity.py b/tests/control_plane/test_public_safe_text_owner_parity.py index 8f7879b4ca..b10b7fc9f2 100644 --- a/tests/control_plane/test_public_safe_text_owner_parity.py +++ b/tests/control_plane/test_public_safe_text_owner_parity.py @@ -138,6 +138,18 @@ def test_public_output_guard_keeps_remote_urls_and_ordinary_prose() -> None: validate_public_safe_value({"value": value}) +@pytest.mark.parametrize( + "value", + ( + "https://docs.example.test./home/overview", + "https://[2001:db8::1]/home/overview", + "https://docs.example.com/?next=/home/overview", + ), +) +def test_vision_checkpoint_keeps_http_links_with_path_shaped_parts(value: str) -> None: + _vision_text(value) + + def _boundary_authority_text(text: str) -> None: """Drive boundary_authority through its public builder, not its helper.""" diff --git a/tests/control_plane/test_public_safety_text_budget.py b/tests/control_plane/test_public_safety_text_budget.py index 0216ce3c90..c4bb37c69b 100644 --- a/tests/control_plane/test_public_safety_text_budget.py +++ b/tests/control_plane/test_public_safety_text_budget.py @@ -79,3 +79,8 @@ def test_a_credential_inside_the_kept_prefix_is_still_refused() -> None: assert public_safe_compact_text("note ordinary prose", limit=40) == ( "note ordinary prose" ) + + +def test_http_link_with_path_shaped_parts_survives_compaction() -> None: + value = "https://[2001:db8::1]/home/overview?next=/tmp/a" + assert public_safe_compact_text(value, limit=200) == value diff --git a/tests/extensions/test_extension_presentation.py b/tests/extensions/test_extension_presentation.py index 1fd65f3356..d861fe3f41 100644 --- a/tests/extensions/test_extension_presentation.py +++ b/tests/extensions/test_extension_presentation.py @@ -836,6 +836,9 @@ def test_publish_projection_dry_run_does_not_load_validator( "///tmp/a.log", "//Users/alex/x", "x=/private/a", + "/home/", + "///var/", + "C:\\", ) @@ -857,6 +860,20 @@ def test_opaque_view_keeps_ordinary_remote_urls_and_prose() -> None: assert validate_opaque_presentation_view(view) == view +PUBLIC_URL_VIEW_VALUES = ( + "https://docs.example.test./home/overview", + "https://[2001:db8::1]/home/overview", + "https://docs.example.com/?next=/home/overview", +) + + +@pytest.mark.parametrize("value", PUBLIC_URL_VIEW_VALUES) +def test_opaque_view_keeps_http_links_with_path_shaped_url_parts(value: str) -> None: + assert validate_opaque_presentation_view({"headline": value}) == { + "headline": value + } + + @pytest.mark.skipif(os.name == "nt", reason="POSIX console-script shebang fixture") def test_projection_publication_rejects_local_path_without_rewriting( tmp_path: Path, @@ -900,3 +917,90 @@ def test_projection_publication_rejects_local_path_without_rewriting( assert projection_file.read_bytes() == previous_bytes assert json.loads(previous_bytes)["payload_sha256"] == first["payload_sha256"] + + +@pytest.mark.parametrize("value", ("/home/", "///var/", "C:\\")) +@pytest.mark.skipif(os.name == "nt", reason="POSIX console-script shebang fixture") +def test_projection_publication_rejects_directory_roots_without_rewriting( + tmp_path: Path, + value: str, +) -> None: + state_file, _ = _installed_projection_extension(tmp_path) + first = publish_extension_projection( + "test-research-extension", + "investment-research", + state_file=state_file, + request={"schema_version": "synthetic_request_v0"}, + execute=True, + ) + projection_file = ( + default_extension_projection_root(state_file) + / "test-research-extension" + / "investment-research.json" + ) + previous_bytes = projection_file.read_bytes() + + invalid = _provider_projection() + projection = invalid["presentation_projection"] + assert isinstance(projection, dict) + view = projection["view"] + assert isinstance(view, dict) + view["headline"] = value + _projection_provider(tmp_path / "provider", projection=invalid) + doctor_installed_extension( + "test-research-extension", + state_file=state_file, + execute=True, + ) + + with pytest.raises(ValueError, match="must not contain a local path"): + publish_extension_projection( + "test-research-extension", + "investment-research", + state_file=state_file, + request={"schema_version": "synthetic_request_v0"}, + execute=True, + ) + + assert projection_file.read_bytes() == previous_bytes + assert json.loads(previous_bytes)["payload_sha256"] == first["payload_sha256"] + + +@pytest.mark.parametrize("value", PUBLIC_URL_VIEW_VALUES) +@pytest.mark.skipif(os.name == "nt", reason="POSIX console-script shebang fixture") +def test_projection_publication_accepts_http_link_and_reads_it_back( + tmp_path: Path, + value: str, +) -> None: + state_file, installed = _installed_projection_extension(tmp_path) + accepted = _provider_projection() + projection = accepted["presentation_projection"] + assert isinstance(projection, dict) + view = projection["view"] + assert isinstance(view, dict) + view["headline"] = value + _projection_provider(tmp_path / "provider", projection=accepted) + doctor_installed_extension( + "test-research-extension", + state_file=state_file, + execute=True, + ) + + receipt = publish_extension_projection( + "test-research-extension", + "investment-research", + state_file=state_file, + request={"schema_version": "synthetic_request_v0"}, + execute=True, + ) + assert receipt["status"] == "published" + assert receipt["readback_verified"] is True + + envelope = read_extension_projection( + state_file=state_file, + extension_id="test-research-extension", + surface_id="investment-research", + extension_revision=str(installed["revision"]), + payload_sha256=str(receipt["payload_sha256"]), + ) + assert envelope["view"]["headline"] == value From d0f1832d61144acfa55bd2193aae2a82cbc6cf7d Mon Sep 17 00:00:00 2001 From: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:46:58 +0800 Subject: [PATCH 4/5] fix(public-boundary): treat home-directory URL paths as URL syntax A home-directory name inside an ordinary http(s) URL is a URL path segment, the same as the /home/ links the presentation guard already keeps. Mask the URL for the /Users/ local-path arm in the Python classifier and the TypeScript Vision checkpoint, pin the row in the shared corpus, and stay raw on the publication tier. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> --- loopx/control_plane/goals/vision_checkpoint.ts | 12 ++++++++++-- loopx/public_safe_text.py | 8 +++++++- tests/fixtures/public_safe_text_corpus.json | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/loopx/control_plane/goals/vision_checkpoint.ts b/loopx/control_plane/goals/vision_checkpoint.ts index 7f900b8f53..c8557ed3f3 100644 --- a/loopx/control_plane/goals/vision_checkpoint.ts +++ b/loopx/control_plane/goals/vision_checkpoint.ts @@ -204,8 +204,9 @@ const HTTP_URL_SURFACE = /\bhttps?:\/\/[^\s`'"<>]+/giu; const maskHttpUrlPaths = (value: string): string => value.replace(HTTP_URL_SURFACE, match => " ".repeat(match.length)); export const CREDENTIAL_WORD_PATTERNS: RegExp[] = [/\bBearer\b/i, /\bpassword\b/i, /\bsecret\b/i]; +const HOME_DIRECTORY_TEXT_PATTERN = /\/Users\//; export const PRIVATE_TEXT_PATTERNS: RegExp[] = [ - /\/Users\//, + HOME_DIRECTORY_TEXT_PATTERN, /\/ext[_]data\//, // Preserve the matcher without matching its own policy source. /lark[o]ffice/i, // Equivalent matcher avoids matching its own policy source. /docs\.internal/i, @@ -362,7 +363,14 @@ function publicSafeTextGuidance(label: string): string { function validatePublicSafeText(label: string, value: string): void { for (const pattern of INTERNAL_STATE_PRIVATE_TEXT_PATTERNS) { - const candidate = pattern === LOCAL_PATH_SHAPE ? maskHttpUrlPaths(value) : value; + // The local-path arms read the URL-masked text: an ordinary http(s) link + // may legitimately carry a /Users/ or /home/ segment, which is URL syntax + // rather than a home-directory reference. Publication-tier callers keep + // reading the raw value. + const candidate = + pattern === LOCAL_PATH_SHAPE || pattern === HOME_DIRECTORY_TEXT_PATTERN + ? maskHttpUrlPaths(value) + : value; if (pattern.test(candidate)) { throw new EffectRuntimeRequestError( `${label} contains a private-looking value; ${publicSafeTextGuidance(label)}`, diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 092f97f761..4dc8790a99 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -680,7 +680,13 @@ def classify_private_text( return None local_path_value = mask_http_url_paths(value) for entry in _CATEGORIZED_PRIVATE_TEXT_PATTERNS: - if entry.category in categories and entry.pattern.search(value): + if entry.category not in categories: + continue + # A public URL may carry a ``/Users/`` segment; the local-path arms read + # the masked text so URL syntax cannot masquerade as a home-directory + # reference. Organization markers and credentials keep the raw value. + candidate = local_path_value if entry.category == CATEGORY_LOCAL_PATH else value + if entry.pattern.search(candidate): return PrivateTextMatch(entry.category, entry.reason, entry.pattern) for pattern, category, reason in _SHAPE_DETECTORS: candidate = local_path_value if category == CATEGORY_LOCAL_PATH else value diff --git a/tests/fixtures/public_safe_text_corpus.json b/tests/fixtures/public_safe_text_corpus.json index 7ad23b88a1..97758ce7ac 100644 --- a/tests/fixtures/public_safe_text_corpus.json +++ b/tests/fixtures/public_safe_text_corpus.json @@ -122,6 +122,12 @@ "template": "metrics published at https://example.com/run-7/metrics.json", "shape": "remote_location_undecided", "note": "The internal-state tier does not decide URLs: the rule these four owners enforced before never rejected one either, and per-face URL policy is the caller-migration work still open in #5136." + }, + { + "id": "ordinary_public_url_home_directory_segment", + "template": "docs live at https://docs.example.test./Users/alice", + "shape": "remote_location_undecided", + "note": "A home-directory name inside an http(s) URL path is URL syntax; only a file:// or path: reference is a local path." } ], "private_looking": [ From 8fb1e868b6bb36fbcb12f869cde90576bbce558f Mon Sep 17 00:00:00 2001 From: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:40:13 +0800 Subject: [PATCH 5/5] test(steward): align monitor test import block with upstream The unused pytest import is already gone on main; keep this file byte-identical so the PR no longer conflicts with the upstream edit that added the import-group separator. Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com> --- tests/test_steward_generic_monitor_todo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_steward_generic_monitor_todo.py b/tests/test_steward_generic_monitor_todo.py index 22d661b67a..f3e57adc83 100644 --- a/tests/test_steward_generic_monitor_todo.py +++ b/tests/test_steward_generic_monitor_todo.py @@ -4,6 +4,7 @@ from datetime import datetime, timedelta, timezone import json from pathlib import Path + from loopx.capabilities.native_chat.steward_monitor import ( StewardMonitor, pump_steward_monitors,