Repository navigation
fix(ui): token revoke button sends DELETE with empty token ID (#4046) - #4047
Conversation
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]>
4819efe to
9927654
Compare
crivetimihai
left a comment
There was a problem hiding this comment.
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.
…#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]>
…#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]>
…#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]>
🔗 Related Issue
Closes #4046
📝 Summary
The token revoke button in the admin UI used an undefined Jinja2 variable
{{token_id}}in itshx-deleteattribute, causingDELETE /admin/tokens/(missing ID) → 404. Additionally, noDELETE /admin/tokens/{id}endpoint exists inadmin.py.Fixed by replacing the broken HTMX
hx-deletewithdata-action="token-revoke", delegating to the existing JSrevokeToken()handler which calls the correctDELETE /tokens/{token_id}endpoint. This also adds the missing confirmation dialog that the HTMX path lacked.🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageAlso I've done Playwright E2E test
pytest tests/playwright/security/test_token_lifecycle.py(passed)✅ Checklist
make black isort pre-commit)📓 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:
isinstance(response, HTMLResponse)without parsing the rendered HTMLrevoke_token()helper has a fallback API path that silently bypasses the broken UI buttonChanges:
tokens_partial.html— Replacehx-delete/hx-swapwithdata-action="token-revoke"test_admin.py— 3 unit tests verifying button attributes and visibility gatingtest_token_lifecycle.py— 2 Playwright E2E tests for UI revoke flow regression