Skip to content

fix(ui): token revoke button sends DELETE with empty token ID (#4046) - #4047

Merged
crivetimihai merged 1 commit into
IBM:mainfrom
kimsehwan96:fix/token-revoke-404
Apr 6, 2026
Merged

crivetimihai merged 1 commit into
IBM:mainfrom
kimsehwan96:fix/token-revoke-404

Conversation

@kimsehwan96

Copy link
Copy Markdown
Contributor

🔗 Related Issue

Closes #4046


📝 Summary

The token revoke button in the admin UI used an undefined Jinja2 variable {{token_id}} in its hx-delete attribute, causing DELETE /admin/tokens/ (missing ID) → 404. Additionally, no DELETE /admin/tokens/{id} endpoint exists in admin.py.

Fixed by replacing the broken HTMX hx-delete with data-action="token-revoke", delegating to the existing JS revokeToken() handler which calls the correct DELETE /tokens/{token_id} endpoint. This also adds the missing confirmation dialog that the HTMX path lacked.


🏷️ Type of Change

  • Bug fix
  • Feature / Enhancement
  • Documentation
  • Refactor
  • Chore (deps, CI, tooling)
  • Other (describe below)

🧪 Verification

Check Command Status
Lint suite make lint pass
Unit tests make test pass
Coverage ≥ 80% make coverage pass

Also I've done Playwright E2E test pytest tests/playwright/security/test_token_lifecycle.py (passed)


✅ Checklist

  • Code formatted (make black isort pre-commit)
  • Tests added/updated for changes
  • Documentation updated (if applicable)
  • No secrets or credentials committed

📓 Notes (optional)

Root cause: tokens_partial.html:104 — {{token_id}} is not a valid template variable in the {% for token in data %} loop. The correct variable is {{token.id}}, which is used correctly on the adjacent line 106 (data-token-id="{{ token.id }}").

This bug was introduced in #2833 and was never caught because:

  1. Unit tests only checked isinstance(response, HTMLResponse) without parsing the rendered HTML
  2. Playwright's revoke_token() helper has a fallback API path that silently bypasses the broken UI button

Changes:

  • tokens_partial.html — Replace hx-delete/hx-swap with data-action="token-revoke"
  • test_admin.py — 3 unit tests verifying button attributes and visibility gating
  • test_token_lifecycle.py — 2 Playwright E2E tests for UI revoke flow regression

The revoke button in tokens_partial.html used an undefined Jinja2
variable `{{token_id}}` in hx-delete, rendering as `/admin/tokens/`
(missing ID) and returning 404. Additionally, no DELETE endpoint
existed at `/admin/tokens/{id}` in admin.py.

Replace the broken HTMX hx-delete with `data-action="token-revoke"`
to delegate to the existing JS `revokeToken()` handler, which calls
the correct `DELETE /tokens/{token_id}` endpoint with confirmation
dialog, error handling, and list refresh.

Signed-off-by: kimsehwan96 <[email protected]>
@crivetimihai
crivetimihai force-pushed the fix/token-revoke-404 branch from 4819efe to 9927654 Compare April 6, 2026 16:28

@crivetimihai crivetimihai left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, @kimsehwan96 — this was a real bug that's been lurking since #2833.

Review

Bug diagnosis is spot-on. {{token_id}} was undefined in the {% for token in data %} loop, so hx-delete rendered as DELETE /admin/tokens/ (empty ID) → 404. And even if the ID had resolved correctly, there's no DELETE /admin/tokens/{id} endpoint in admin.py — the actual endpoint is DELETE /tokens/{token_id} in routers/tokens.py.

Fix is correct and consistent. Replacing the broken HTMX path with data-action="token-revoke" delegates to the existing revokeToken() JS handler in tokens.js, which already:

  • Calls the correct DELETE /tokens/{tokenId} endpoint
  • Includes a confirmation dialog (which the HTMX path lacked)
  • Sends auth headers and a revocation reason
  • Shows success/error notifications and refreshes the list

This is consistent with the other token actions (token-details, token-usage) in the same panel, all of which use the data-action + event delegation pattern.

Tests are well-written. The 3 unit tests verify the rendered HTML attributes and visibility gating, and the 2 Playwright E2E tests specifically click the UI button (bypassing the page object's fallback API path) to catch exactly this class of regression.

No security or performance concerns. The JS handler uses proper auth headers and hits the permissioned endpoint.

Changes made

I rebased onto main (clean, no conflicts) and force-pushed to your branch — no code changes, just the rebase.

LGTM — approving.

@crivetimihai
crivetimihai merged commit 12efe98 into IBM:main Apr 6, 2026
34 of 35 checks passed
jonpspri pushed a commit that referenced this pull request Apr 10, 2026
…#4047)

The revoke button in tokens_partial.html used an undefined Jinja2
variable `{{token_id}}` in hx-delete, rendering as `/admin/tokens/`
(missing ID) and returning 404. Additionally, no DELETE endpoint
existed at `/admin/tokens/{id}` in admin.py.

Replace the broken HTMX hx-delete with `data-action="token-revoke"`
to delegate to the existing JS `revokeToken()` handler, which calls
the correct `DELETE /tokens/{token_id}` endpoint with confirmation
dialog, error handling, and list refresh.

Signed-off-by: kimsehwan96 <[email protected]>
claudia-gray pushed a commit that referenced this pull request Apr 13, 2026
…#4047)

The revoke button in tokens_partial.html used an undefined Jinja2
variable `{{token_id}}` in hx-delete, rendering as `/admin/tokens/`
(missing ID) and returning 404. Additionally, no DELETE endpoint
existed at `/admin/tokens/{id}` in admin.py.

Replace the broken HTMX hx-delete with `data-action="token-revoke"`
to delegate to the existing JS `revokeToken()` handler, which calls
the correct `DELETE /tokens/{token_id}` endpoint with confirmation
dialog, error handling, and list refresh.

Signed-off-by: kimsehwan96 <[email protected]>
msureshkumar88 pushed a commit that referenced this pull request May 13, 2026
…#4047)

The revoke button in tokens_partial.html used an undefined Jinja2
variable `{{token_id}}` in hx-delete, rendering as `/admin/tokens/`
(missing ID) and returning 404. Additionally, no DELETE endpoint
existed at `/admin/tokens/{id}` in admin.py.

Replace the broken HTMX hx-delete with `data-action="token-revoke"`
to delegate to the existing JS `revokeToken()` handler, which calls
the correct `DELETE /tokens/{token_id}` endpoint with confirmation
dialog, error handling, and list refresh.

Signed-off-by: kimsehwan96 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Token revoke button in admin UI sends DELETE with empty token ID (404)

2 participants