Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-15
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Proposal

## Why

The masker replaced a lower-case name after the word `Secret` or `token` with `<masked-token>`, 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 <value>`), 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.
Original file line number Diff line number Diff line change
@@ -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 <masked-token>`

#### Scenario: An assignment
- **WHEN** the text holds `auth_token: my-service-account`
- **THEN** the masker masks the value as the assignment form does
Original file line number Diff line number Diff line change
@@ -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 <base>..HEAD).
19 changes: 19 additions & 0 deletions openspec/specs/secret-masking/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<masked-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 <masked-token>`

#### Scenario: An assignment
- **WHEN** the text holds `auth_token: my-service-account`
- **THEN** the masker masks the value as the assignment form does
16 changes: 15 additions & 1 deletion src/devops_cli/security/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<masked-token>")

Expand Down
14 changes: 14 additions & 0 deletions tests/security/test_secret_redaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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