From 7706c35f9726c26e607587c294c4ecd045b73635 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 10:51:04 +0800 Subject: [PATCH 1/9] fix(presentation): reject raw credential values at the public boundary The presentation boundary table carried labeled assignments for three key names and issuer-prefixed provider tokens, but bearer/basic headers, long and short password/secret/token assignments (including quoted JSON keys), URL userinfo, and connector/quoted values still passed as public-safe. The owning classifier already recognized those shapes as credential category. Compose the shared assignment source and the owner's floor-free assignment, connector, quoted and Basic shapes into the presentation table, and collapse duplicate warning labels. Signed-off-by: JasonBuildAI --- loopx/presentation/public_safety.py | 14 +- loopx/public_safe_text.py | 69 +++++++-- ..._presentation_credential_value_boundary.py | 131 ++++++++++++++++++ 3 files changed, 200 insertions(+), 14 deletions(-) create mode 100644 tests/control_plane/test_presentation_credential_value_boundary.py diff --git a/loopx/presentation/public_safety.py b/loopx/presentation/public_safety.py index 0e3a6e9d5b..fd974f1a4b 100644 --- a/loopx/presentation/public_safety.py +++ b/loopx/presentation/public_safety.py @@ -47,11 +47,15 @@ def scan_public_boundary_text(text: str) -> dict[str, object]: Returns ``{"ok": bool, "warnings": [label, ...]}``. The scanner is the canonical public/private boundary check for generated presentation text; the static-site exporter and the session dash generator share it. + Duplicate labels are collapsed because one value can satisfy overlapping + credential shapes. """ - warnings = [ - label - for label, pattern in PUBLIC_BOUNDARY_PATTERNS - if pattern.search(text) - ] + warnings = list( + dict.fromkeys( + label + for label, pattern in PUBLIC_BOUNDARY_PATTERNS + if pattern.search(text) + ) + ) return {"ok": not warnings, "warnings": warnings} diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 2ac49459f1..85cc785a73 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -368,6 +368,20 @@ def _mask(match: re.Match[str]) -> str: r"\bpypi-[a-z0-9_-]{20,}|" r"\beyj[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\b" ) +# Raw credential values whose *value*, not a key name the presentation table +# already labels (`api_key`, `auth_token`, `access_token`), carries the secret. +# The classifier composite and the presentation boundary table both consume this +# one source, so a new value shape cannot be recognized by only one of them. The +# three labeled keys stay out on purpose: repeating them here would make one +# value produce two presentation warnings for the same bytes. +CREDENTIAL_VALUE_PATTERN_SOURCE = ( + r"\bbearer\s+[a-z0-9._~+/=-]{16,}|" + r"\b[a-z][a-z0-9+.-]*://[^/\s:@`'\"<>]+:[^/\s@`'\"<>]+@[^\s`'\"<>]*|" + r"\b(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|secret[_-]?key|access[_-]?key)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + r"\bpassword[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" + r"\bsecret[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" + r"\b(?:refresh[_-]?token|token)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}" +) PRESENTATION_PUBLIC_BOUNDARY_PATTERNS: tuple[ tuple[str, re.Pattern[str]], ... ] = ( @@ -399,29 +413,66 @@ def _mask(match: re.Match[str]) -> str: # An issuer prefix is its own label: a token carried in tool output or a # pasted log rarely arrives as an assignment, so the assignment arm never # sees it. Composed from the shared source the sibling scanners consume - # (#7636), case-folded like the presentation local-path arms. + # (#7636), case-folded like the presentation local-path arms. It stays ahead + # of the value arm so an issuer-prefixed token keeps its specific warning. ( "provider token", re.compile(r"(?i)(?:" + PROVIDER_TOKEN_SHAPE_PATTERN_SOURCE + r")"), ), + # A value-bearing credential is its own label. The assignment arm above only + # sees three key names; a dash page, a manager detail return or a peer + # conclusion can carry an Authorization Bearer/Basic header, a + # password/secret assignment, a URL with embedded userinfo, or a + # refresh/bare token instead. + # Those shapes were already known to the owning classifier + # (`SECRET_LIKE_SURFACE_PATTERN`); the presentation policy simply never + # consulted them, so it certified the raw values as public-safe. + ( + "credential value", + re.compile(r"(?i)(?:" + CREDENTIAL_VALUE_PATTERN_SOURCE + r")"), + ), + # The owner also treats a credential word followed by ':'/'=' as an + # assignment regardless of value length, including the quoted JSON-key form. + # Consult that shape so `password=hunter2` cannot be released by the shared + # assignment arm's {12,} floor. + ( + "credential value", + LABELED_CREDENTIAL_ASSIGNMENT_PATTERN, + ), + # Connector and quoted spellings are already owned by the text classifier; + # the presentation policy now consults those same shapes instead of releasing + # "password is hunter2hunter2" or `client secret is "abcd1234"` as prose. They + # share the "credential value" label; the scanner collapses duplicate labels. + ( + "credential value", + CONNECTED_CREDENTIAL_VALUE_SHAPE_PATTERN, + ), + ( + "credential value", + QUOTED_CREDENTIAL_VALUE_SHAPE_PATTERN, + ), + # The authorization header has a second standard scheme. `_BASIC_CREDENTIAL_VALUE` + # already owns that shape for the text classifier, so the presentation policy + # consults the same owner instead of restating a base64 shape here. + ( + "basic-auth credential value", + _BASIC_CREDENTIAL_VALUE, + ), ) # Refs #5136: one definition for "this string carries a raw remote location". # Three validators each restated the same scheme list, and the canonical # public-safety owner had no counterpart, so a fourth caller had to invent one. REMOTE_LOCATION_SURFACE_PATTERN = re.compile(r"(?i)\b(?:https?|file|s3|gs|tos|hdfs)://") SECRET_LIKE_SURFACE_PATTERN = re.compile( - r"(?i)(?:\bbearer\s+[a-z0-9._~+/=-]{16,}|" - r"\b[a-z][a-z0-9+.-]*://[^/\s:@`'\"<>]+:[^/\s@`'\"<>]+@[^\s`'\"<>]*|" - r"\b(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|(?:access|api|secret)[_-]?key)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" - r"\b(?:ak|sk)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + r"(?i)(?:" + CREDENTIAL_VALUE_PATTERN_SOURCE + + r"|\b(?:ak|sk)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" r"(?]{12,}|" - r"\b(?:password|secret)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" + r"\baccess[_-]?token[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" + r"\bapi[_-]?key[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" r"-{3,}\s*BEGIN (?:[A-Z]+ )?PRIVATE KEY[\s\S]*?" - r"(?:-{3,}\s*END (?:[A-Z]+ )?PRIVATE KEY-{3,}|$)|" - r"\btoken[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,})" + r"(?:-{3,}\s*END (?:[A-Z]+ )?PRIVATE KEY-{3,}|$))" ) # Shared identifier shapes stay here with the sibling public-safe text shapes. diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py new file mode 100644 index 0000000000..997ddcc4fb --- /dev/null +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -0,0 +1,131 @@ +"""The presentation boundary rejects raw credential values, not just key labels. + +`scan_public_boundary_text` is the single gate used by the session dash, the +`loopx dash` HTML path, manager-channel detail returns and non-private peer +result publication. It carried labeled assignments for three key names and +issuer-prefixed provider tokens, but a live value could still arrive as an +`Authorization: Bearer` header, a password/secret assignment, a URL with +embedded userinfo, or a refresh/bare token. The owning classifier already named +those shapes as `credential`; the presentation policy now consumes the same +source, so the same bytes cannot be private to the owner and public here. +""" + +from __future__ import annotations + +import pytest + +from loopx.chat.manager_details import _text as manager_text +from loopx.presentation import public_safety +from loopx.public_safe_text import classify_private_text + + +CREDENTIAL_VALUES = { + "authorization bearer header": ( + "GET /v1/items\nAuthorization: Bearer 8f3a1c9e7b2d4f6a0c5e8b1d3f7a9c2e\n" + ), + "password assignment": 'service password = "correct-horse-battery-staple"\n', + "secret access key assignment": ( + "secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\n" + ), + "url userinfo": "https://deploy:sup3rsecret@internal.example.com/repo\n", + "refresh token assignment": "refresh_token=abcdefghijklmnop\n", + "bare token assignment": "token=abcdefghijklmnop\n", +} + + +@pytest.mark.parametrize("value", CREDENTIAL_VALUES.values(), ids=CREDENTIAL_VALUES.keys()) +def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> None: + assert public_safety.scan_public_boundary_text(value) == { + "ok": False, + "warnings": ["credential value"], + } + match = classify_private_text(value) + assert match is not None + assert match.category == "credential" + + +@pytest.mark.parametrize( + "text", + [ + "Send a Bearer token in the Authorization header; never paste the value.", + "The password rotation policy applies to every service account.", + "Authorization: Bearer ", + "https://example.com/a", + ], +) +def test_credential_prose_stays_public(text: str) -> None: + assert public_safety.scan_public_boundary_text(text) == { + "ok": True, + "warnings": [], + } + + +SHORT_ASSIGNMENT_VALUES = [ + "password=hunter2", + "token=abc123", + "secret: hunter2", + '{"password": "hunter2"}', + '{"token": "abc123"}', + '{"secret": "abcd1234"}', +] + + +@pytest.mark.parametrize("value", SHORT_ASSIGNMENT_VALUES) +def test_short_and_json_key_assignments_fail_the_boundary(value: str) -> None: + assert public_safety.scan_public_boundary_text(value) == { + "ok": False, + "warnings": ["credential value"], + } + match = classify_private_text(value) + assert match is not None + assert match.category == "credential" + + +def test_connector_and_quoted_credential_values_fail_the_boundary() -> None: + for value in ( + "password is hunter2hunter2", + 'client secret is "abcd1234"', + ): + assert public_safety.scan_public_boundary_text(value) == { + "ok": False, + "warnings": ["credential value"], + } + match = classify_private_text(value) + assert match is not None + assert match.category == "credential" + + +def test_basic_authorization_header_uses_the_owner_shape() -> None: + value = "GET /v1/items\nAuthorization: Basic dXNlcjpwYXNzd29yZA==\n" + + assert public_safety.scan_public_boundary_text(value) == { + "ok": False, + "warnings": ["basic-auth credential value"], + } + match = classify_private_text(value) + assert match is not None + assert match.category == "credential" + + +def test_existing_labels_keep_one_warning_per_value() -> None: + token = "ghp_" + "A1b2C3d4E5f6G7h8I9j0K1l2M3n4" + + # The provider and labeled-assignment arms still own their warnings; the + # shared value source must not add a second label for the same bytes. + assert public_safety.scan_public_boundary_text(token) == { + "ok": False, + "warnings": ["provider token"], + } + assert public_safety.scan_public_boundary_text(f"deploy used access_token={token}") == { + "ok": False, + "warnings": ["credential assignment", "provider token"], + } + + +def test_manager_detail_return_omits_a_raw_bearer_value() -> None: + text = "next step: call the endpoint with Authorization: Bearer " + "8f3a" * 8 + + assert manager_text(text) == "[sensitive text omitted]" + assert manager_text("next step: rotate the expired Bearer credential") == ( + "next step: rotate the expired Bearer credential" + ) From 93aa10575b855019f98da59c7c5cba35c5a8b937 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 13:40:35 +0800 Subject: [PATCH 2/9] fix(presentation): keep hyphenated design tokens public The label-only credential arm matched the suffix of a hyphenated identifier, so a stylesheet such as '--color-token: #3b82f6' read as a short credential assignment and a valid static site stopped packaging. Presentation now asks the owner's label set at a token start, keeps the owner's value arms, and restores the cross-language credential mirror that the canonical refactor left behind. Refs #9424. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 60 +++++++++-------- ..._presentation_credential_value_boundary.py | 21 ++++++ tests/test_static_site_presentation.py | 65 +++++++++++++++++++ 3 files changed, 120 insertions(+), 26 deletions(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 85cc785a73..7706ce256c 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -368,19 +368,27 @@ def _mask(match: re.Match[str]) -> str: r"\bpypi-[a-z0-9_-]{20,}|" r"\beyj[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\b" ) -# Raw credential values whose *value*, not a key name the presentation table -# already labels (`api_key`, `auth_token`, `access_token`), carries the secret. -# The classifier composite and the presentation boundary table both consume this -# one source, so a new value shape cannot be recognized by only one of them. The -# three labeled keys stay out on purpose: repeating them here would make one -# value produce two presentation warnings for the same bytes. -CREDENTIAL_VALUE_PATTERN_SOURCE = ( +# Presentation packages whole public assets -- stylesheets, rendered pages, +# CLI help -- rather than one operational field. There a hyphen joins one +# identifier, so a design token such as `--color-token`, or a flag such as +# `--client-secret`, is a compound name and not a label beside an operator. +# `\b` alone fires after that hyphen, so the classifier's assignment arms read +# the suffix as a short credential and a valid site stopped packaging. The +# presentation policy asks the same label set at a token start; the +# free-standing `\b` form stays the classifier contract, and a field-name +# compound remains the owner's separate opt-in arm (Refs #5136). +_PRESENTATION_LABEL_TOKEN_START = r"(?]+:[^/\s@`'\"<>]+@[^\s`'\"<>]*|" - r"\b(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|secret[_-]?key|access[_-]?key)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" - r"\bpassword[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" - r"\bsecret[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" - r"\b(?:refresh[_-]?token|token)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}" + + _PRESENTATION_LABEL_TOKEN_START + + r"(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|secret[_-]?key|access[_-]?key)" + r"[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + + _PRESENTATION_LABEL_TOKEN_START + + CREDENTIAL_LABEL_PATTERN_SOURCE + + r"[\"']?\s*[:=]|" + + _PRESENTATION_LABEL_TOKEN_START + + r"refresh[_-]?token[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}" ) PRESENTATION_PUBLIC_BOUNDARY_PATTERNS: tuple[ tuple[str, re.Pattern[str]], ... @@ -426,18 +434,15 @@ def _mask(match: re.Match[str]) -> str: # refresh/bare token instead. # Those shapes were already known to the owning classifier # (`SECRET_LIKE_SURFACE_PATTERN`); the presentation policy simply never - # consulted them, so it certified the raw values as public-safe. - ( - "credential value", - re.compile(r"(?i)(?:" + CREDENTIAL_VALUE_PATTERN_SOURCE + r")"), - ), - # The owner also treats a credential word followed by ':'/'=' as an - # assignment regardless of value length, including the quoted JSON-key form. - # Consult that shape so `password=hunter2` cannot be released by the shared - # assignment arm's {12,} floor. + # consulted them, so it certified the raw values as public-safe. The + # presentation composition keeps that owner's value arms and asks the label + # arms at a token start, so a hyphenated design-token name is not read as a + # short assignment, while `password=hunter2` still needs no length floor. ( "credential value", - LABELED_CREDENTIAL_ASSIGNMENT_PATTERN, + re.compile( + r"(?i)(?:" + PRESENTATION_CREDENTIAL_VALUE_PATTERN_SOURCE + r")" + ), ), # Connector and quoted spellings are already owned by the text classifier; # the presentation policy now consults those same shapes instead of releasing @@ -464,15 +469,18 @@ def _mask(match: re.Match[str]) -> str: # public-safety owner had no counterpart, so a fourth caller had to invent one. REMOTE_LOCATION_SURFACE_PATTERN = re.compile(r"(?i)\b(?:https?|file|s3|gs|tos|hdfs)://") SECRET_LIKE_SURFACE_PATTERN = re.compile( - r"(?i)(?:" + CREDENTIAL_VALUE_PATTERN_SOURCE - + r"|\b(?:ak|sk)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + r"(?i)(?:\bbearer\s+[a-z0-9._~+/=-]{16,}|" + r"\b[a-z][a-z0-9+.-]*://[^/\s:@`'\"<>]+:[^/\s@`'\"<>]+@[^\s`'\"<>]*|" + r"\b(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|(?:access|api|secret)[_-]?key)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + r"\b(?:ak|sk)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" r"(?]{12,}|" - r"\bapi[_-]?key[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + r"\b(?:access|refresh)[_-]?token[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" + r"\b(?:password|secret)[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}|" r"-{3,}\s*BEGIN (?:[A-Z]+ )?PRIVATE KEY[\s\S]*?" - r"(?:-{3,}\s*END (?:[A-Z]+ )?PRIVATE KEY-{3,}|$))" + r"(?:-{3,}\s*END (?:[A-Z]+ )?PRIVATE KEY-{3,}|$)|" + r"\btoken[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,})" ) # Shared identifier shapes stay here with the sibling public-safe text shapes. diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index 997ddcc4fb..93409c3050 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -95,6 +95,27 @@ def test_connector_and_quoted_credential_values_fail_the_boundary() -> None: assert match.category == "credential" +@pytest.mark.parametrize( + "value", + [ + ":root { --color-token: #3b82f6; --space-md: 16px; }\n", + ":root{--color-token:#3b82f6;--space-md:16px}\n", + ":root { --color-token: var(--palette-blue-500); }\n", + "body { color: var(--color-token); }\n", + "Pass --client-secret= to configure the connector.\n", + "Pass --access-key=EXAMPLEKEYVALUE to configure the provider.\n", + ], + ids=("css token", "minified css", "css var value", "css var use", "flag secret", "flag access key"), +) +def test_hyphenated_design_names_are_not_credential_assignments(value: str) -> None: + # A hyphen joins one identifier in a stylesheet or CLI help. The suffix + # (`--color-token`) is a name, not a credential label beside an operator. + assert public_safety.scan_public_boundary_text(value) == { + "ok": True, + "warnings": [], + } + + def test_basic_authorization_header_uses_the_owner_shape() -> None: value = "GET /v1/items\nAuthorization: Basic dXNlcjpwYXNzd29yZA==\n" diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index b04014725e..fa7f867b02 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -353,3 +353,68 @@ def test_cli_package_preview_is_read_only_and_exposes_publisher_as_first_class_p assert payload["dry_run"] is True assert payload["publisher"]["kind"] == "github-pages" assert output.exists() is False + + +def _cli_package(site: Path, output: Path, state: Path) -> int: + return main( + [ + "--format", + "json", + "presentation", + "package", + "--site-dir", + str(site), + "--output-dir", + str(output), + "--state-dir", + str(state), + "--site-id", + "cli-demo", + "--publisher", + "local", + "--desktop-visual-check", + "passed", + "--mobile-visual-check", + "passed", + "--link-check", + "passed", + "--execute", + ] + ) + + +def test_cli_package_keeps_a_css_design_token_public( + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + stylesheet = ( + ":root { --color-token: #3b82f6; --space-md: 16px; }\n" + "body { color: var(--color-token); }\n" + ) + site = _site(tmp_path) + (site / "styles.css").write_text(stylesheet, encoding="utf-8") + output = tmp_path / "publish" + + assert _cli_package(site, output, tmp_path / "state") == 0 + payload = json.loads(capsys.readouterr().out) + assert payload["write_performed"] is True + assert (output / "styles.css").read_text(encoding="utf-8") == stylesheet + + +def test_cli_package_still_rejects_a_credential_value_in_an_asset( + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + site = _site(tmp_path) + (site / "styles.css").write_text( + ":root { --color-token: #3b82f6; }\n" + "/* token=abc123 */\n", + encoding="utf-8", + ) + output = tmp_path / "publish" + + assert _cli_package(site, output, tmp_path / "state") == 2 + payload = json.loads(capsys.readouterr().out) + assert payload["ok"] is False + assert "credential value" in payload["error"] + assert not output.exists() From 52648db4e180953c2d1be1acf0dfbd062d9e0e02 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 14:49:53 +0800 Subject: [PATCH 3/9] fix(presentation): ask for value evidence after a credential label A presentation help page introduces a field with Password: or Token: followed by an explanatory sentence. The label arm rejected any colon, so two ordinary sign-in help pages failed packaging with credential value. A colon now needs a quoted value, a token carrying a digit or base64 character, or an opaque letter run; = stays an assignment without that check. password=hunter2, JSON key assignments and secret: hunter2 still fail, and the CSS design-token controls remain green. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 47 ++++++++++++++++--- ..._presentation_credential_value_boundary.py | 16 +++++++ tests/test_static_site_presentation.py | 26 ++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 7706ce256c..5c48513e74 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -373,22 +373,57 @@ def _mask(match: re.Match[str]) -> str: # identifier, so a design token such as `--color-token`, or a flag such as # `--client-secret`, is a compound name and not a label beside an operator. # `\b` alone fires after that hyphen, so the classifier's assignment arms read -# the suffix as a short credential and a valid site stopped packaging. The -# presentation policy asks the same label set at a token start; the +# the suffix as a short credential and a valid site stopped packaging. +# +# A colon is also how an ordinary help page introduces a field, `Password:` or +# `Token:` followed by an explanatory sentence. Presentation therefore accepts +# `=` as an assignment without a shape check (a help heading does not spell +# `Password =`) but asks for value evidence after a colon: a quoted value, a +# token carrying a digit or base64 character, or a letter-only run long enough +# to be opaque. That keeps `password=hunter2`, `{"token": "abc123"}` and +# `secret: hunter2` while releasing `Password: sign in with the account you +# use for email`. +# The presentation policy asks these label sets at a token start; the # free-standing `\b` form stays the classifier contract, and a field-name # compound remains the owner's separate opt-in arm (Refs #5136). _PRESENTATION_LABEL_TOKEN_START = r"(?]+:[^/\s@`'\"<>]+@[^\s`'\"<>]*|" + _PRESENTATION_LABEL_TOKEN_START - + r"(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|secret[_-]?key|access[_-]?key)" - r"[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]+|" + + _PRESENTATION_KEY_LABELS_SOURCE + + r"[\"']?\s*=\s*" + r"[\"']?[^\s`'\"<>]+|" + + _PRESENTATION_LABEL_TOKEN_START + + _PRESENTATION_KEY_LABELS_SOURCE + + r"[\"']?\s*:\s*" + + _PRESENTATION_COLON_VALUE_SOURCE + + r"|" + + _PRESENTATION_LABEL_TOKEN_START + + CREDENTIAL_LABEL_PATTERN_SOURCE + + r"[\"']?\s*=\s*" + r"[\"']?[^\s`'\"<>]+|" + _PRESENTATION_LABEL_TOKEN_START + CREDENTIAL_LABEL_PATTERN_SOURCE - + r"[\"']?\s*[:=]|" + + r"[\"']?\s*:\s*" + + _PRESENTATION_COLON_VALUE_SOURCE + + r"|" + + _PRESENTATION_LABEL_TOKEN_START + + r"refresh[_-]?token[\"']?\s*=\s*[\"']?[^\s`'\"<>]{12,}|" + _PRESENTATION_LABEL_TOKEN_START - + r"refresh[_-]?token[\"']?\s*[=:]\s*[\"']?[^\s`'\"<>]{12,}" + + r"refresh[_-]?token[\"']?\s*:\s*" + + _PRESENTATION_COLON_VALUE_SOURCE ) PRESENTATION_PUBLIC_BOUNDARY_PATTERNS: tuple[ tuple[str, re.Pattern[str]], ... diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index 93409c3050..bbf7374360 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -51,7 +51,21 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "The password rotation policy applies to every service account.", "Authorization: Bearer ", "https://example.com/a", + "

Password:

Sign in with the password you use for your email.

", + "

Token:

Ask your administrator to issue a token for this device.

", + "Password: sign in with the account you use for email.\n", + "Token: contact your administrator for a new token.\n", ], + ids=( + "bearer prose", + "password prose", + "redacted bearer", + "plain url", + "password heading", + "token heading", + "password sentence", + "token sentence", + ), ) def test_credential_prose_stays_public(text: str) -> None: assert public_safety.scan_public_boundary_text(text) == { @@ -64,9 +78,11 @@ def test_credential_prose_stays_public(text: str) -> None: "password=hunter2", "token=abc123", "secret: hunter2", + "token: abc123def456ghi", '{"password": "hunter2"}', '{"token": "abc123"}', '{"secret": "abcd1234"}', + "refresh_token: abcdefghijklmnop", ] diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index fa7f867b02..b980a07d09 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -401,6 +401,32 @@ def test_cli_package_keeps_a_css_design_token_public( assert (output / "styles.css").read_text(encoding="utf-8") == stylesheet +def test_cli_package_keeps_login_help_headings_public( + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + site = _site(tmp_path) + help_page = ( + "

Account help

\n" + "

Password:

Sign in with the password you use for email.

\n" + "\n" + ) + token_page = ( + "

Device setup

\n" + "

Token:

Ask your administrator to issue a token for this device.

\n" + "\n" + ) + (site / "help.html").write_text(help_page, encoding="utf-8") + (site / "token-help.html").write_text(token_page, encoding="utf-8") + output = tmp_path / "publish" + + assert _cli_package(site, output, tmp_path / "state") == 0 + payload = json.loads(capsys.readouterr().out) + assert payload["write_performed"] is True + assert (output / "help.html").read_text(encoding="utf-8") == help_page + assert (output / "token-help.html").read_text(encoding="utf-8") == token_page + + def test_cli_package_still_rejects_a_credential_value_in_an_asset( tmp_path: Path, capsys: pytest.CaptureFixture[str], From 6d354bf9459cf594ba4a23e8e9727b291483cc69 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 15:34:53 +0800 Subject: [PATCH 4/9] fix(presentation): treat numeric account rules as public help A help page states Password: 12 characters or Token: 24 hours; the colon value arm read the number as credential evidence and stopped packaging. A quantity with a length or time unit is now kept out of the value arms, while a bare number (Password: 12345678), a mixed value ( oken: abc123), JSON key assignments and the CSS design-token controls keep their existing results. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 18 ++++++++++++- ..._presentation_credential_value_boundary.py | 9 +++++++ tests/test_static_site_presentation.py | 26 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 5c48513e74..e58eb50f0e 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -390,8 +390,24 @@ def _mask(match: re.Match[str]) -> str: _PRESENTATION_KEY_LABELS_SOURCE = ( r"(?:(?:aws[_-]?)?secret[_-]?access[_-]?key|secret[_-]?key|access[_-]?key)" ) +# Account help often states a rule as `Password: 12 characters` or +# `Token: 24 hours`. A bare number after a label is not by itself a secret; +# when it is a quantity with a length or time unit it is a public rule. The +# negative lookahead keeps that shape out of the value-evidence arms while a +# bare number (`Password: 12345678`) and a mixed value (`token: abc123`) still +# fail closed. +_PRESENTATION_RULE_QUANTITY_SOURCE = ( + r"(?![\"']?\d+(?:\.\d+)?" + r"(?:\s*[-\u2013]\s*\d+|\+)?" + r"(?:\s+or\s+(?:more|fewer|less))?" + r"\s*[-\u2013]?\s*" + r"(?:characters?|chars?|letters?|digits?|symbols?" + r"|hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s" + r"|days?|d|weeks?|months?|years?)\b)" +) _PRESENTATION_COLON_VALUE_SOURCE = ( - r"(?:" + _PRESENTATION_RULE_QUANTITY_SOURCE + + r"(?:" r"[\"'][^\"'\n]+[\"']|" + _SHAPE_VALUE_TOKEN_SOURCE + r"|" diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index bbf7374360..c82f83f47b 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -55,6 +55,10 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "

Token:

Ask your administrator to issue a token for this device.

", "Password: sign in with the account you use for email.\n", "Token: contact your administrator for a new token.\n", + "Password: 12 characters minimum.\n", + "Password: 8+ characters\n", + "Token: 24 hours.\n", + "Token: 24-hour expiry\n", ], ids=( "bearer prose", @@ -65,6 +69,10 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "token heading", "password sentence", "token sentence", + "password length rule", + "password length plus", + "token expiry rule", + "token expiry hyphen", ), ) def test_credential_prose_stays_public(text: str) -> None: @@ -79,6 +87,7 @@ def test_credential_prose_stays_public(text: str) -> None: "token=abc123", "secret: hunter2", "token: abc123def456ghi", + "Password: 12345678", '{"password": "hunter2"}', '{"token": "abc123"}', '{"secret": "abcd1234"}', diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index b980a07d09..a243f39e4f 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -427,6 +427,32 @@ def test_cli_package_keeps_login_help_headings_public( assert (output / "token-help.html").read_text(encoding="utf-8") == token_page +def test_cli_package_keeps_numeric_account_rules_public( + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + site = _site(tmp_path) + password_page = ( + "

Password requirements

\n" + "

Password: 12 characters minimum.

\n" + "\n" + ) + token_page = ( + "

Token lifetime

\n" + "

Token: 24 hours.

\n" + "\n" + ) + (site / "password-length.html").write_text(password_page, encoding="utf-8") + (site / "token-expiry.html").write_text(token_page, encoding="utf-8") + output = tmp_path / "publish" + + assert _cli_package(site, output, tmp_path / "state") == 0 + payload = json.loads(capsys.readouterr().out) + assert payload["write_performed"] is True + assert (output / "password-length.html").read_text(encoding="utf-8") == password_page + assert (output / "token-expiry.html").read_text(encoding="utf-8") == token_page + + def test_cli_package_still_rejects_a_credential_value_in_an_asset( tmp_path: Path, capsys: pytest.CaptureFixture[str], From 0e57e52e9e8b966d8aef40a4e1cd653f5a51ad4b Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 15:50:54 +0800 Subject: [PATCH 5/9] fix(presentation): cover word ranges and business-day rules A help page states Password: 8 to 64 characters or Token: 2 business days; the quantity guard accepted symbol ranges and bare units but not the word range or a qualified day unit, so the number still matched as a credential value. Word ranges ( o, hrough, nd), qualified units (usiness, working, calendar, ull, consecutive) and workdays now count as public rule quantities. Bare numbers and mixed values still fail. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 11 ++++++----- .../test_presentation_credential_value_boundary.py | 4 ++++ tests/test_static_site_presentation.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index e58eb50f0e..c1f4841d81 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -393,17 +393,18 @@ def _mask(match: re.Match[str]) -> str: # Account help often states a rule as `Password: 12 characters` or # `Token: 24 hours`. A bare number after a label is not by itself a secret; # when it is a quantity with a length or time unit it is a public rule. The -# negative lookahead keeps that shape out of the value-evidence arms while a -# bare number (`Password: 12345678`) and a mixed value (`token: abc123`) still -# fail closed. +# negative lookahead also covers word ranges (`8 to 64 characters`) and +# qualified units (`2 business days`) while a bare number (`Password: +# 12345678`) and a mixed value (`token: abc123`) still fail closed. _PRESENTATION_RULE_QUANTITY_SOURCE = ( r"(?![\"']?\d+(?:\.\d+)?" - r"(?:\s*[-\u2013]\s*\d+|\+)?" + r"(?:\s*[-\u2013]\s*\d+|\s+(?:to|through|and)\s+\d+|\+)?" r"(?:\s+or\s+(?:more|fewer|less))?" r"\s*[-\u2013]?\s*" + r"(?:(?:business|working|calendar|full|consecutive)[-\s]+)?" r"(?:characters?|chars?|letters?|digits?|symbols?" r"|hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s" - r"|days?|d|weeks?|months?|years?)\b)" + r"|days?|workdays?|d|weeks?|months?|years?)\b)" ) _PRESENTATION_COLON_VALUE_SOURCE = ( _PRESENTATION_RULE_QUANTITY_SOURCE diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index c82f83f47b..c1ed99b445 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -57,8 +57,10 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "Token: contact your administrator for a new token.\n", "Password: 12 characters minimum.\n", "Password: 8+ characters\n", + "Password: 8 to 64 characters.\n", "Token: 24 hours.\n", "Token: 24-hour expiry\n", + "Token: 2 business days.\n", ], ids=( "bearer prose", @@ -71,8 +73,10 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "token sentence", "password length rule", "password length plus", + "password length range", "token expiry rule", "token expiry hyphen", + "token business days", ), ) def test_credential_prose_stays_public(text: str) -> None: diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index a243f39e4f..72bb94dcda 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -444,6 +444,18 @@ def test_cli_package_keeps_numeric_account_rules_public( ) (site / "password-length.html").write_text(password_page, encoding="utf-8") (site / "token-expiry.html").write_text(token_page, encoding="utf-8") + password_range = ( + "

Password requirements

\n" + "

Password: 8 to 64 characters.

\n" + "\n" + ) + token_business_days = ( + "

Token lifetime

\n" + "

Token: 2 business days.

\n" + "\n" + ) + (site / "password-range.html").write_text(password_range, encoding="utf-8") + (site / "token-business-days.html").write_text(token_business_days, encoding="utf-8") output = tmp_path / "publish" assert _cli_package(site, output, tmp_path / "state") == 0 @@ -451,6 +463,8 @@ def test_cli_package_keeps_numeric_account_rules_public( assert payload["write_performed"] is True assert (output / "password-length.html").read_text(encoding="utf-8") == password_page assert (output / "token-expiry.html").read_text(encoding="utf-8") == token_page + assert (output / "password-range.html").read_text(encoding="utf-8") == password_range + assert (output / "token-business-days.html").read_text(encoding="utf-8") == token_business_days def test_cli_package_still_rejects_a_credential_value_in_an_asset( From 15a82acd9600f6a2533687f2d7af866d9f765284 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 16:06:43 +0800 Subject: [PATCH 6/9] fix(presentation): accept character-class password rules A help page states Password: 12 alphanumeric characters or Password: 8 to 64 ASCII characters. The quantity guard knew qualified units but not character-class qualifiers, so the leading number still matched as a credential value. Up to two letter/hyphen qualifiers before a length unit now count as a public rule; bare numbers (Password: 12345678), unitless ranges and mixed credential values still fail. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 13 +++++----- ..._presentation_credential_value_boundary.py | 4 +++ tests/test_static_site_presentation.py | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index c1f4841d81..8412a4a9dc 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -393,15 +393,16 @@ def _mask(match: re.Match[str]) -> str: # Account help often states a rule as `Password: 12 characters` or # `Token: 24 hours`. A bare number after a label is not by itself a secret; # when it is a quantity with a length or time unit it is a public rule. The -# negative lookahead also covers word ranges (`8 to 64 characters`) and -# qualified units (`2 business days`) while a bare number (`Password: -# 12345678`) and a mixed value (`token: abc123`) still fail closed. +# negative lookahead also covers word ranges (`8 to 64 characters`), +# qualified units (`2 business days`) and character classes (`12 alphanumeric +# characters`) while a bare number (`Password: 12345678`) and a mixed value +# (`token: abc123`) still fail closed. _PRESENTATION_RULE_QUANTITY_SOURCE = ( r"(?![\"']?\d+(?:\.\d+)?" - r"(?:\s*[-\u2013]\s*\d+|\s+(?:to|through|and)\s+\d+|\+)?" + r"(?:\s*[-\u2013\u2014]\s*\d+|\s+(?:to|through|and)\s+\d+|\+)?" r"(?:\s+or\s+(?:more|fewer|less))?" - r"\s*[-\u2013]?\s*" - r"(?:(?:business|working|calendar|full|consecutive)[-\s]+)?" + r"\s*[-\u2013\u2014]?\s*" + r"(?:[A-Za-z][A-Za-z-]*[-\s]+){0,2}" r"(?:characters?|chars?|letters?|digits?|symbols?" r"|hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s" r"|days?|workdays?|d|weeks?|months?|years?)\b)" diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index c1ed99b445..6defcbd6ae 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -58,6 +58,8 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "Password: 12 characters minimum.\n", "Password: 8+ characters\n", "Password: 8 to 64 characters.\n", + "Password: 12 alphanumeric characters.\n", + "Password: 8 to 64 ASCII characters.\n", "Token: 24 hours.\n", "Token: 24-hour expiry\n", "Token: 2 business days.\n", @@ -74,6 +76,8 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "password length rule", "password length plus", "password length range", + "password alphanumeric rule", + "password ascii range rule", "token expiry rule", "token expiry hyphen", "token business days", diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index 72bb94dcda..2c13d8f1eb 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -467,6 +467,32 @@ def test_cli_package_keeps_numeric_account_rules_public( assert (output / "token-business-days.html").read_text(encoding="utf-8") == token_business_days +def test_cli_package_keeps_character_class_rules_public( + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + site = _site(tmp_path) + alphanumeric_page = ( + "

Password requirements

\n" + "

Password: 12 alphanumeric characters.

\n" + "\n" + ) + ascii_page = ( + "

Password requirements

\n" + "

Password: 8 to 64 ASCII characters.

\n" + "\n" + ) + (site / "password-alphanumeric.html").write_text(alphanumeric_page, encoding="utf-8") + (site / "password-ascii.html").write_text(ascii_page, encoding="utf-8") + output = tmp_path / "publish" + + assert _cli_package(site, output, tmp_path / "state") == 0 + payload = json.loads(capsys.readouterr().out) + assert payload["write_performed"] is True + assert (output / "password-alphanumeric.html").read_text(encoding="utf-8") == alphanumeric_page + assert (output / "password-ascii.html").read_text(encoding="utf-8") == ascii_page + + def test_cli_package_still_rejects_a_credential_value_in_an_asset( tmp_path: Path, capsys: pytest.CaptureFixture[str], From 027c452248ce6ce24970bcad462740fb8492c394 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Wed, 25 Nov 2026 20:15:54 +0800 Subject: [PATCH 7/9] fix(presentation): keep quoted interface labels public A help page introduces a field with `Password:` or `Token:` and then quotes a button, `"Forgot password?"` or `"Copy token"`. The quoted colon arm accepted any quoted phrase, so packaging stopped. A quoted value now needs one credential-shaped token: a digit/base64/symbol character or a long letters-only run. Multi-word Title Case labels stay public, while `{"token": "abc123"}` and `Password: "hunter2"` still fail. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 7 ++++- ..._presentation_credential_value_boundary.py | 5 ++++ tests/test_static_site_presentation.py | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index 8412a4a9dc..c490a033d5 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -410,7 +410,12 @@ def _mask(match: re.Match[str]) -> str: _PRESENTATION_COLON_VALUE_SOURCE = ( _PRESENTATION_RULE_QUANTITY_SOURCE + r"(?:" - r"[\"'][^\"'\n]+[\"']|" + # A quoted value needs a single credential-shaped token: a digit or + # base64/symbol character, or a long opaque letters-only run. A quoted + # interface label (`"Forgot password?"`, `"Copy token"`) has spaces or + # ordinary Title Case words and stays public help. + r"[\"'](?=[^\s\"'`<>]*[0-9+/=@#$%^&*_!])[^\s\"'`<>]+[\"']|" + r"[\"'][A-Za-z]{16,}[\"']|" + _SHAPE_VALUE_TOKEN_SOURCE + r"|" + _OPAQUE_VALUE_RUN_SOURCE diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index 6defcbd6ae..ae0b967e16 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -60,6 +60,8 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "Password: 8 to 64 characters.\n", "Password: 12 alphanumeric characters.\n", "Password: 8 to 64 ASCII characters.\n", + "Password: \"Forgot password?\" is the link to use.\n", + "Token: \"Copy token\" is the button to use.\n", "Token: 24 hours.\n", "Token: 24-hour expiry\n", "Token: 2 business days.\n", @@ -78,6 +80,8 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "password length range", "password alphanumeric rule", "password ascii range rule", + "forgot password button", + "copy token button", "token expiry rule", "token expiry hyphen", "token business days", @@ -99,6 +103,7 @@ def test_credential_prose_stays_public(text: str) -> None: '{"password": "hunter2"}', '{"token": "abc123"}', '{"secret": "abcd1234"}', + 'Password: "hunter2"', "refresh_token: abcdefghijklmnop", ] diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index 2c13d8f1eb..ea460af538 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -493,6 +493,32 @@ def test_cli_package_keeps_character_class_rules_public( assert (output / "password-ascii.html").read_text(encoding="utf-8") == ascii_page +def test_cli_package_keeps_quoted_button_labels_public( + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + site = _site(tmp_path) + forgot_page = ( + "

Sign in help

\n" + '

Password: "Forgot password?" is the link to use.

\n' + "\n" + ) + copy_page = ( + "

Device setup

\n" + '

Token: "Copy token" is the button to use.

\n' + "\n" + ) + (site / "forgot-password.html").write_text(forgot_page, encoding="utf-8") + (site / "copy-token.html").write_text(copy_page, encoding="utf-8") + output = tmp_path / "publish" + + assert _cli_package(site, output, tmp_path / "state") == 0 + payload = json.loads(capsys.readouterr().out) + assert payload["write_performed"] is True + assert (output / "forgot-password.html").read_text(encoding="utf-8") == forgot_page + assert (output / "copy-token.html").read_text(encoding="utf-8") == copy_page + + def test_cli_package_still_rejects_a_credential_value_in_an_asset( tmp_path: Path, capsys: pytest.CaptureFixture[str], From 0f3d2bc9dbbc4df66626daa3006d980b6dc8b2a0 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Thu, 26 Nov 2026 12:21:22 +0800 Subject: [PATCH 8/9] fix(presentation): recognize account policy wording A numeric composition rule and a punctuated quoted action label were still treated as credential values. Treat counted uppercase, lowercase, and number classes as public policy quantities, and require quoted values to carry the same digit or base64 evidence as unquoted values. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 12 ++++++++---- .../test_presentation_credential_value_boundary.py | 4 ++++ tests/test_static_site_presentation.py | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index c490a033d5..f9ec61a894 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -394,8 +394,9 @@ def _mask(match: re.Match[str]) -> str: # `Token: 24 hours`. A bare number after a label is not by itself a secret; # when it is a quantity with a length or time unit it is a public rule. The # negative lookahead also covers word ranges (`8 to 64 characters`), -# qualified units (`2 business days`) and character classes (`12 alphanumeric -# characters`) while a bare number (`Password: 12345678`) and a mixed value +# qualified units (`2 business days`), character classes (`12 alphanumeric +# characters`) and counted composition rules (`1 uppercase, 1 lowercase, and +# 1 number`) while a bare number (`Password: 12345678`) and a mixed value # (`token: abc123`) still fail closed. _PRESENTATION_RULE_QUANTITY_SOURCE = ( r"(?![\"']?\d+(?:\.\d+)?" @@ -403,7 +404,8 @@ def _mask(match: re.Match[str]) -> str: r"(?:\s+or\s+(?:more|fewer|less))?" r"\s*[-\u2013\u2014]?\s*" r"(?:[A-Za-z][A-Za-z-]*[-\s]+){0,2}" - r"(?:characters?|chars?|letters?|digits?|symbols?" + r"(?:characters?|chars?|letters?|digits?|numbers?|symbols?" + r"|uppercase|lowercase" r"|hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s" r"|days?|workdays?|d|weeks?|months?|years?)\b)" ) @@ -414,7 +416,9 @@ def _mask(match: re.Match[str]) -> str: # base64/symbol character, or a long opaque letters-only run. A quoted # interface label (`"Forgot password?"`, `"Copy token"`) has spaces or # ordinary Title Case words and stays public help. - r"[\"'](?=[^\s\"'`<>]*[0-9+/=@#$%^&*_!])[^\s\"'`<>]+[\"']|" + r"[\"']" + + _SHAPE_VALUE_TOKEN_SOURCE + + r"[\"']|" r"[\"'][A-Za-z]{16,}[\"']|" + _SHAPE_VALUE_TOKEN_SOURCE + r"|" diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index ae0b967e16..e1bee1e3a7 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -60,7 +60,9 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "Password: 8 to 64 characters.\n", "Password: 12 alphanumeric characters.\n", "Password: 8 to 64 ASCII characters.\n", + "Password: 1 uppercase, 1 lowercase, and 1 number.\n", "Password: \"Forgot password?\" is the link to use.\n", + "Password: \"Continue!\" is the button to use.\n", "Token: \"Copy token\" is the button to use.\n", "Token: 24 hours.\n", "Token: 24-hour expiry\n", @@ -80,7 +82,9 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "password length range", "password alphanumeric rule", "password ascii range rule", + "password composition rule", "forgot password button", + "punctuated action button", "copy token button", "token expiry rule", "token expiry hyphen", diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index ea460af538..938edd435d 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -482,8 +482,14 @@ def test_cli_package_keeps_character_class_rules_public( "

Password: 8 to 64 ASCII characters.

\n" "\n" ) + composition_page = ( + "

Password composition

\n" + "

Password: 1 uppercase, 1 lowercase, and 1 number.

\n" + "\n" + ) (site / "password-alphanumeric.html").write_text(alphanumeric_page, encoding="utf-8") (site / "password-ascii.html").write_text(ascii_page, encoding="utf-8") + (site / "password-composition.html").write_text(composition_page, encoding="utf-8") output = tmp_path / "publish" assert _cli_package(site, output, tmp_path / "state") == 0 @@ -491,6 +497,7 @@ def test_cli_package_keeps_character_class_rules_public( assert payload["write_performed"] is True assert (output / "password-alphanumeric.html").read_text(encoding="utf-8") == alphanumeric_page assert (output / "password-ascii.html").read_text(encoding="utf-8") == ascii_page + assert (output / "password-composition.html").read_text(encoding="utf-8") == composition_page def test_cli_package_keeps_quoted_button_labels_public( @@ -508,8 +515,14 @@ def test_cli_package_keeps_quoted_button_labels_public( '

Token: "Copy token" is the button to use.

\n' "\n" ) + continue_page = ( + "

Device setup

\n" + '

Password: "Continue!" is the button to use.

\n' + "\n" + ) (site / "forgot-password.html").write_text(forgot_page, encoding="utf-8") (site / "copy-token.html").write_text(copy_page, encoding="utf-8") + (site / "continue-button.html").write_text(continue_page, encoding="utf-8") output = tmp_path / "publish" assert _cli_package(site, output, tmp_path / "state") == 0 @@ -517,6 +530,7 @@ def test_cli_package_keeps_quoted_button_labels_public( assert payload["write_performed"] is True assert (output / "forgot-password.html").read_text(encoding="utf-8") == forgot_page assert (output / "copy-token.html").read_text(encoding="utf-8") == copy_page + assert (output / "continue-button.html").read_text(encoding="utf-8") == continue_page def test_cli_package_still_rejects_a_credential_value_in_an_asset( From 0f250de8225a66bcb76211a8f601a944a1b00650 Mon Sep 17 00:00:00 2001 From: JasonBuildAI Date: Thu, 26 Nov 2026 13:04:53 +0800 Subject: [PATCH 9/9] fix(presentation): keep code-point length rules public A password length measured in Unicode code points was still read as a credential value. Treat code points, code units, bytes and UTF byte lengths as public policy measurement units while preserving bare-number and mixed-value rejection. Signed-off-by: JasonBuildAI --- loopx/public_safe_text.py | 10 +++++++--- .../test_presentation_credential_value_boundary.py | 4 ++++ tests/test_static_site_presentation.py | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/loopx/public_safe_text.py b/loopx/public_safe_text.py index f9ec61a894..390a0ad1e3 100644 --- a/loopx/public_safe_text.py +++ b/loopx/public_safe_text.py @@ -395,9 +395,10 @@ def _mask(match: re.Match[str]) -> str: # when it is a quantity with a length or time unit it is a public rule. The # negative lookahead also covers word ranges (`8 to 64 characters`), # qualified units (`2 business days`), character classes (`12 alphanumeric -# characters`) and counted composition rules (`1 uppercase, 1 lowercase, and -# 1 number`) while a bare number (`Password: 12345678`) and a mixed value -# (`token: abc123`) still fail closed. +# characters`), counted composition rules (`1 uppercase, 1 lowercase, and +# 1 number`) and encoded-length units (`12 Unicode code points`) while a bare +# number (`Password: 12345678`) and a mixed value (`token: abc123`) still fail +# closed. _PRESENTATION_RULE_QUANTITY_SOURCE = ( r"(?![\"']?\d+(?:\.\d+)?" r"(?:\s*[-\u2013\u2014]\s*\d+|\s+(?:to|through|and)\s+\d+|\+)?" @@ -406,6 +407,9 @@ def _mask(match: re.Match[str]) -> str: r"(?:[A-Za-z][A-Za-z-]*[-\s]+){0,2}" r"(?:characters?|chars?|letters?|digits?|numbers?|symbols?" r"|uppercase|lowercase" + r"|code[-\s]?points?|code[-\s]?units?" + r"|(?:utf-?8|utf-?16|utf-?32)\s+(?:code[-\s]?units?|bytes?)" + r"|bytes?" r"|hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s" r"|days?|workdays?|d|weeks?|months?|years?)\b)" ) diff --git a/tests/control_plane/test_presentation_credential_value_boundary.py b/tests/control_plane/test_presentation_credential_value_boundary.py index e1bee1e3a7..04e5c67857 100644 --- a/tests/control_plane/test_presentation_credential_value_boundary.py +++ b/tests/control_plane/test_presentation_credential_value_boundary.py @@ -61,6 +61,8 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "Password: 12 alphanumeric characters.\n", "Password: 8 to 64 ASCII characters.\n", "Password: 1 uppercase, 1 lowercase, and 1 number.\n", + "Password: 12 Unicode code points.\n", + "Password: 32 UTF-8 bytes.\n", "Password: \"Forgot password?\" is the link to use.\n", "Password: \"Continue!\" is the button to use.\n", "Token: \"Copy token\" is the button to use.\n", @@ -83,6 +85,8 @@ def test_a_raw_credential_value_fails_the_presentation_boundary(value: str) -> N "password alphanumeric rule", "password ascii range rule", "password composition rule", + "password unicode code points rule", + "password utf8 bytes rule", "forgot password button", "punctuated action button", "copy token button", diff --git a/tests/test_static_site_presentation.py b/tests/test_static_site_presentation.py index 938edd435d..3a682f7a68 100644 --- a/tests/test_static_site_presentation.py +++ b/tests/test_static_site_presentation.py @@ -487,9 +487,15 @@ def test_cli_package_keeps_character_class_rules_public( "

Password: 1 uppercase, 1 lowercase, and 1 number.

\n" "\n" ) + code_points_page = ( + "

Password length

\n" + "

Password: 12 Unicode code points.

\n" + "\n" + ) (site / "password-alphanumeric.html").write_text(alphanumeric_page, encoding="utf-8") (site / "password-ascii.html").write_text(ascii_page, encoding="utf-8") (site / "password-composition.html").write_text(composition_page, encoding="utf-8") + (site / "password-code-points.html").write_text(code_points_page, encoding="utf-8") output = tmp_path / "publish" assert _cli_package(site, output, tmp_path / "state") == 0 @@ -498,6 +504,7 @@ def test_cli_package_keeps_character_class_rules_public( assert (output / "password-alphanumeric.html").read_text(encoding="utf-8") == alphanumeric_page assert (output / "password-ascii.html").read_text(encoding="utf-8") == ascii_page assert (output / "password-composition.html").read_text(encoding="utf-8") == composition_page + assert (output / "password-code-points.html").read_text(encoding="utf-8") == code_points_page def test_cli_package_keeps_quoted_button_labels_public(