From a37d7c86b326dec8c0145718bb2839717df30902 Mon Sep 17 00:00:00 2001 From: Sava Znatnov Date: Thu, 19 Nov 2026 02:08:33 +0300 Subject: [PATCH 1/3] fix: keep the OAuth access token out of a TokenResponse repr access_token was a plain str, so repr, a traceback or a log line showed the token. It is a SecretStr now; the device flow reads it with get_secret_value(). Co-Authored-By: Claude Opus 5.5 --- src/ycli/yandex/status/cli.py | 2 +- src/ycli/yandex/status/oauth_models.py | 4 ++-- tests/unit/yandex/status/test_login_cli.py | 6 +++++- tests/unit/yandex/status/test_oauth_client.py | 11 ++++++++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ycli/yandex/status/cli.py b/src/ycli/yandex/status/cli.py index 42e7d8278..9e79faf63 100644 --- a/src/ycli/yandex/status/cli.py +++ b/src/ycli/yandex/status/cli.py @@ -268,7 +268,7 @@ def _device_flow(oauth_client: OAuthClient, device_name: str | None, console: Co while True: result: TokenPollResult = oauth_client.poll_token(device.device_code) if result.token is not None: - return result.token.access_token + return result.token.access_token.get_secret_value() if not result.pending: typer.secho(f"Authorization failed: {result.error}", fg=typer.colors.RED, err=True) raise typer.Exit(1) diff --git a/src/ycli/yandex/status/oauth_models.py b/src/ycli/yandex/status/oauth_models.py index 65c9719a0..0889e4e94 100644 --- a/src/ycli/yandex/status/oauth_models.py +++ b/src/ycli/yandex/status/oauth_models.py @@ -4,7 +4,7 @@ these are plain data with no serialization logic (that lives in ``output.py``). """ -from pydantic import Field +from pydantic import Field, SecretStr from ycli.yandex.models import APIModel @@ -36,7 +36,7 @@ class TokenResponse(APIModel): token is always present. """ - access_token: str = Field(description="The issued OAuth access token.") + access_token: SecretStr = Field(description="The issued OAuth access token.") token_type: str | None = Field(default=None, description="Type of the token, e.g. `bearer`.") expires_in: int | None = Field(default=None, description="Seconds until the token expires.") scope: str | None = Field(default=None, description="Scopes the token was granted.") diff --git a/tests/unit/yandex/status/test_login_cli.py b/tests/unit/yandex/status/test_login_cli.py index 9b05edbb3..4d0f00660 100644 --- a/tests/unit/yandex/status/test_login_cli.py +++ b/tests/unit/yandex/status/test_login_cli.py @@ -6,6 +6,7 @@ from types import SimpleNamespace import pytest +from pydantic import SecretStr from rich.console import Console from rich.live import Live from typer.testing import CliRunner @@ -318,7 +319,10 @@ def test_device_flow_shows_code_in_a_panel_and_returns_token(monkeypatch): buf = StringIO() console = Console(file=buf, force_terminal=False, width=80) client = _FakeOAuth( - [TokenPollResult(pending=True), TokenPollResult(token=TokenResponse(access_token="tok-9"))] + [ + TokenPollResult(pending=True), + TokenPollResult(token=TokenResponse(access_token=SecretStr("tok-9"))), + ] ) token = _device_flow(client, None, console) # ty: ignore[invalid-argument-type] assert token == "tok-9" diff --git a/tests/unit/yandex/status/test_oauth_client.py b/tests/unit/yandex/status/test_oauth_client.py index ef9ba6c7b..27438d1b1 100644 --- a/tests/unit/yandex/status/test_oauth_client.py +++ b/tests/unit/yandex/status/test_oauth_client.py @@ -2,6 +2,7 @@ import httpx2 import pytest +from pydantic import SecretStr from ycli.yandex.errors import ( YandexAuthError, @@ -10,6 +11,7 @@ YandexServerError, ) from ycli.yandex.status.client import OAuthClient +from ycli.yandex.status.oauth_models import TokenResponse DEVICE_CODE_URL = "https://oauth.yandex.ru/device/code" TOKEN_URL = "https://oauth.yandex.ru/token" @@ -61,7 +63,8 @@ def test_poll_token_success(api): assert result.pending is False assert result.error == "" assert result.token is not None - assert result.token.access_token == "tok-abc" + assert result.token.access_token.get_secret_value() == "tok-abc" + assert "tok-abc" not in repr(result.token) def test_poll_token_pending(api): @@ -125,3 +128,9 @@ def test_a_lost_connection_is_a_typed_error(monkeypatch): ) with pytest.raises(YandexConnectionError, match="ConnectError"): _client().request_device_code() + + +def test_a_token_response_does_not_show_the_token_in_its_repr(): + response = TokenResponse(access_token=SecretStr("tok-abc")) + assert "tok-abc" not in repr(response) + assert "tok-abc" not in str(response) From c2829e210b3e5c20cf1ebbdc2edbe1f29571bffa Mon Sep 17 00:00:00 2001 From: Sava Znatnov Date: Thu, 19 Nov 2026 02:21:00 +0300 Subject: [PATCH 2/3] fix: run the CI secret scan with the gitleaks version pre-commit uses The action pinned 8.24.3 while .pre-commit-config.yaml runs 8.30.1, so a secret could pass one gate and fail the other. GITLEAKS_VERSION is the action's documented input. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 324ab4b09..8d81d14b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,3 +126,5 @@ jobs: uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Same version as .pre-commit-config.yaml; the action pins an older one by default. + GITLEAKS_VERSION: 8.30.1 From 66213303793bd2c6701aa8076996a0192f87479e Mon Sep 17 00:00:00 2001 From: Sava Znatnov Date: Thu, 19 Nov 2026 02:21:05 +0300 Subject: [PATCH 3/3] fix: catch a bare Yandex OAuth token in the secret scan The default rules do not know the y0_ token shape, so a token pasted without a key name passed both gates. One rule on top of the defaults. Co-Authored-By: Claude Opus 5.5 --- .gitleaks.toml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitleaks.toml diff --git a/.gitleaks.toml b/.gitleaks.toml new file mode 100644 index 000000000..1ed7f631a --- /dev/null +++ b/.gitleaks.toml @@ -0,0 +1,9 @@ +# Extends the built-in rules with the one token shape they do not know. +[extend] +useDefault = true + +[[rules]] +id = "yandex-oauth-token" +description = "A bare Yandex OAuth token: y0_ then 40 or more URL-safe characters." +regex = '''y0_[A-Za-z0-9_-]{40,}''' +keywords = ["y0_"]