Skip to content

P1 auth: require type=access in /me (refresh token must not be an identity) #76

Closed

Description

@SlavaKuntsov

Follow-up из ревью фазы 16 (#48/#49/#53).

Пункт про lowercase-миграцию users.email снят: dev-стенд и данные удалены (compose down -v), регистронезависимость (#49) работает на пустой БД без миграций.

Осталось (Low):
decode_token требует exp/sub, но не type — GET /api/v1/auth/me примет 7-дневный refresh-токен как access-идентичность. Фикс: в /me проверять payload.get("type") == "access" (в Go-мидлварях уже сделано в #53).

Verify: /me с refresh-токеном → 401; с access-токеном → 200.

Activity

  1. changed the title [-]P1 auth: lowercase migration for existing users.email and type check in /me[/-] [+]P1 auth: require type=access in /me (refresh token must not be an identity)[/+] on Sep 18, 2026
  2. SlavaKuntsov commented on Sep 29, 2026

    @SlavaKuntsov
    OwnerAuthor

    Agent review — iteration 1

    Findings

    • None. Independent reviewer examined origin/main..8a5c619, both full source files, and re-ran checks. Confirmed: type-check placed after signature/exp validation and before sub/UUID parsing/DB query (services/auth/src/routers/auth.py:112); forged type claims fail signature verification; tokens without type fail closed (secure default, consistent with Go middleware from P1 infra: fail fast on empty JWT_SECRET/INTERNAL_TOKEN and require exp in JWT #53); decode_token has no other unchecked callers (/refresh already type-checks).

    Verdict

    ready for PR

    Verification

    • uv run pytest tests/test_auth.py -v — 19 passed (incl. new test_me_with_refresh_token_rejected: refresh → 401, DB never hit; existing test_me_success: access → 200)
    • uv run flake8 src tests — clean; uv run mypy src — clean
    • black --check on tests/test_auth.py fails on pre-existing long lines already present on origin/main (not introduced by this change)
  3. SlavaKuntsov commented on Sep 29, 2026

    @SlavaKuntsov
    OwnerAuthor

    Ready for review

    Implemented

    Acceptance criteria

    • /me с refresh-токеном → 401 (identity не утекает, запрос к БД не выполняется)
    • /me с access-токеном → 200 (test_me_success)

    Verification

    • uv run pytest tests/test_auth.py -v — 19 passed
    • uv run flake8 src tests / uv run mypy src — clean
    • make e2e — not run: change is covered by unit tests at the token-parsing boundary; no end-to-end auth flow change

    Review cycle

    • Iterations: 1 (no findings)
    • Remaining risks: none

    Suggested PR title

    fix(auth): require type=access in /me

  4. SlavaKuntsov commented on Sep 29, 2026

    @SlavaKuntsov
    OwnerAuthor

    Pull request opened

    #81 — will auto-close via Closes #76 on merge.

    Project status: Review (synced after PR creation).

    Verification

    • uv run pytest tests/test_auth.py -v — 19 passed
    • uv run flake8 src tests / uv run mypy src — clean

    Remaining risks

    None (make e2e не гонялся — e2e-флоу auth не менялся, изменение покрыто юнит-тестами).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions