diff --git a/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/.openspec.yaml b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/.openspec.yaml new file mode 100644 index 0000000000..a01998ffe1 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-15 diff --git a/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/proposal.md b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/proposal.md new file mode 100644 index 0000000000..2d56f90f38 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/proposal.md @@ -0,0 +1,40 @@ +# Proposal + +## Why + +The masker replaced a lower-case name after the word `Secret` or `token` with ``, so `devops roadmap intake` refused a candidate whose body named Secret `devops-cli` or the subcommand `token revoke-self` (#5240). + +## What Changes + +- Add `_has_a_token_shape` to `src/devops_cli/security/sanitizer.py`: a value after a space-separated keyword masks only with a digit, a dot, an internal capital, or a length of 24 or more. A lower-case hyphenated name stays. +- Keep the wider rule of `_mask_literal` for the assignment forms (`token:`, `token=`, a quoted value, `--token `), and keep `_looks_like_a_credential` for them. +- Add the two negative cases in `tests/security/test_secret_redaction.py`, built from parts. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `secret-masking`: a lower-case name after a keyword is not a credential. + +## Impact + +- Code: `src/devops_cli/security/sanitizer.py` +- Tests: `tests/security/test_secret_redaction.py` + +## Feasibility + +- Read on `origin/main`, 2026-11-15. `src/devops_cli/security/sanitizer.py:342` holds the space-separated rule, and `:73:def _mask_credential_like_value(` gates it. +- `:202:def _mask_literal(` holds the assignment forms. +- `uv run pytest tests/security/test_secret_redaction.py` passes after the change with 289 cases. + +## Existing Tool Considered + +The masker holds its rule table and tests. The change narrows one rule: about 1,000 tokens to build and 100 a quarter to keep. + +## Dependencies + +None. diff --git a/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/specs/secret-masking/spec.md b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/specs/secret-masking/spec.md new file mode 100644 index 0000000000..9a5c18434f --- /dev/null +++ b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/specs/secret-masking/spec.md @@ -0,0 +1,20 @@ +## ADDED Requirements + +### Requirement: A lower-case name after a keyword is not a credential +The space-separated keyword rule SHALL mask the value after `token`, `bearer`, `secret`, `password` or `api_key` only when the value holds a digit, a dot, an internal capital, or 24 characters or more. A lower-case name with hyphens SHALL stay as written. The assignment forms SHALL keep the wider rule of `_mask_literal`. + +#### Scenario: A Kubernetes object name +- **WHEN** the text holds `Secret devops-cli` +- **THEN** the masker returns the text unchanged + +#### Scenario: A subcommand +- **WHEN** the text holds `token revoke-self` +- **THEN** the masker returns the text unchanged + +#### Scenario: A token after a keyword +- **WHEN** the text holds `token abc123def456ghi789` +- **THEN** the masker returns `token ` + +#### Scenario: An assignment +- **WHEN** the text holds `auth_token: my-service-account` +- **THEN** the masker masks the value as the assignment form does diff --git a/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/tasks.md b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/tasks.md new file mode 100644 index 0000000000..bc81d89f24 --- /dev/null +++ b/openspec/changes/archive/2026-11-15-5240-narrow-the-token-masker/tasks.md @@ -0,0 +1,16 @@ +# Tasks + +## 1. Keep a name after a keyword + +Reads: `src/devops_cli/security/sanitizer.py`, `tests/security/test_secret_redaction.py`. + +Changes: `src/devops_cli/security/sanitizer.py`, `tests/security/test_secret_redaction.py`. + +- [x] 1.1 Add the two negative cases and watch them fail. + - Verification: `$ uv run devops ci test tests/security/test_secret_redaction.py` +- [x] 1.2 Narrow the space-separated rule and keep every positive case. + - Verification: `$ uv run devops ci test tests/security/test_secret_redaction.py` + +## Workflow follow-up + +- Pending a person: review the diff in tuicr (tuicr -r ..HEAD). diff --git a/openspec/specs/secret-masking/spec.md b/openspec/specs/secret-masking/spec.md index d276844378..da95c8ed1a 100644 --- a/openspec/specs/secret-masking/spec.md +++ b/openspec/specs/secret-masking/spec.md @@ -199,3 +199,22 @@ The secret masking system SHALL mask a credential value that a quote mark opened #### Scenario: A closing quote mark of the other kind - **WHEN** secret masking processes `token='AGJ4EXAMPLE1234567890" next` - **THEN** the result is `token=" next` + +### Requirement: A lower-case name after a keyword is not a credential +The space-separated keyword rule SHALL mask the value after `token`, `bearer`, `secret`, `password` or `api_key` only when the value holds a digit, a dot, an internal capital, or 24 characters or more. A lower-case name with hyphens SHALL stay as written. The assignment forms SHALL keep the wider rule of `_mask_literal`. + +#### Scenario: A Kubernetes object name +- **WHEN** the text holds `Secret devops-cli` +- **THEN** the masker returns the text unchanged + +#### Scenario: A subcommand +- **WHEN** the text holds `token revoke-self` +- **THEN** the masker returns the text unchanged + +#### Scenario: A token after a keyword +- **WHEN** the text holds `token abc123def456ghi789` +- **THEN** the masker returns `token ` + +#### Scenario: An assignment +- **WHEN** the text holds `auth_token: my-service-account` +- **THEN** the masker masks the value as the assignment form does diff --git a/src/devops_cli/security/sanitizer.py b/src/devops_cli/security/sanitizer.py index d7f60cb2c5..a8b88919c2 100644 --- a/src/devops_cli/security/sanitizer.py +++ b/src/devops_cli/security/sanitizer.py @@ -68,10 +68,24 @@ def _looks_like_a_credential(value: str) -> bool: return any(char.isupper() for char in value[1:]) +def _has_a_token_shape(value: str) -> bool: + """Whether a value after a space-separated keyword reads as a token, not a name (#5240). + + A name such as `devops-cli` after "Secret", or `revoke-self` after "token", carries only + lower-case words and hyphens. A token carries a digit, an internal capital, or a length no + English word reaches. The assignment forms keep the wider rule of `_mask_literal`. + """ + if len(value) >= _CREDENTIAL_MIN_OPAQUE_LENGTH: + return True + if any(char.isdigit() or char == "." for char in value): + return True + return any(char.isupper() for char in value[1:]) + + def _mask_credential_like_value(match: re.Match[str]) -> str: """Replace a keyword-prefixed value only when it looks like a credential.""" value = match.group(1) - if not _looks_like_a_credential(value): + if not _looks_like_a_credential(value) or not _has_a_token_shape(value): return match.group(0) return match.group(0).replace(value, "") diff --git a/tests/security/test_secret_redaction.py b/tests/security/test_secret_redaction.py index 9bb59cfef5..e9becc9ad3 100644 --- a/tests/security/test_secret_redaction.py +++ b/tests/security/test_secret_redaction.py @@ -1003,3 +1003,17 @@ def test_a_quote_stays_unless_it_closes_a_quote_that_opened_the_value( """The mask takes a closing quote only together with the quote that opened the value. A quote of the other kind is not that quote.""" assert redact_text(text, syntax=syntax) == masked + + +def test_a_resource_name_after_secret_is_not_masked() -> None: + """The word `Secret` in front of a Kubernetes resource name stays readable (#5240).""" + text = "The Kubernetes object of kind " + "Secret" + " " + "devops" + "-" + "cli is absent." + + assert mask_secrets(text) == text + + +def test_a_subcommand_after_token_is_not_masked() -> None: + """The vault group `token` before its subcommand stays readable (#5240).""" + text = "Run `devops vault " + "token" + " " + "revoke" + "-" + "self`." + + assert mask_secrets(text) == text