fix(auth): unwrap configmanager Items in require_auth_token#1136
Merged
Conversation
`require_auth_token` was passing `configmanager.Item` wrappers straight
into `verify_auth_token`, where `bytes.fromhex(public_key)` and the
`int > Item` comparison both raised `TypeError`. Those errors were
swallowed by the `except Exception: return False` in
`verify_auth_token`, so every token validation silently returned False
and `/api/v0/price/{hash}/recalculate` (and any other
`@require_auth_token` route) returned 401 for valid tokens.
Call `.value` on the two `Item` accessors before handing them to
`verify_auth_token`, and add a regression test that exercises the
decorator with a real `Config` so future similar mistakes are caught.
Follow-up to #884.
foxpatch-aleph
approved these changes
May 14, 2026
foxpatch-aleph
left a comment
There was a problem hiding this comment.
This is a focused, correct fix for a real bug where configmanager.Item wrappers were passed to functions expecting primitive types, causing silent authentication failures. The two-line change correctly unwraps the items with .value, and the two regression tests exercise the actual decorator path with real configmanager.Config instances to prevent regression. Clean, minimal, well-documented.
tests/toolkit/test_ecdsa.py (line 262): Trivial nit: the second _ for _other_public_key = generate_key_pair()[1] would be slightly more readable than a bare _ in a different scope — but this is cosmetic and fine as-is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #884.
require_auth_tokenwas passingconfigmanager.Itemwrappers straight intoverify_auth_token, which then forwarded them tobytes.fromhex(public_key_hex)and thecurrent_time - timestamp > max_age_secondscomparison. Both raiseTypeErroron non-primitive arguments:Those errors were swallowed by the
except Exception: return Falseinsideverify_auth_token, so every token validation silently returned False — the endpoint/api/v0/price/{hash}/recalculate(and any future@require_auth_token-decorated route) was effectively dead even after #884 fixed thePublicKey.from_hexAttributeError.Fix
Call
.valueon the twoItemaccessors inrequire_auth_tokenbefore handing them toverify_auth_token:config = get_config() auth_config = config.aleph.auth - public_key = auth_config.public_key - max_age = auth_config.max_token_age + public_key = auth_config.public_key.value + max_age = auth_config.max_token_age.valueTests
The existing tests in
tests/toolkit/test_ecdsa.pyexercisedverify_signature/verify_auth_tokenwith raw strings — that's why this bug slipped through. Added two regression tests that drive therequire_auth_tokendecorator with a realconfigmanager.Config(soItemwrappers are present, matching the production case):test_require_auth_token_unwraps_configmanager_items— valid token → 200test_require_auth_token_rejects_invalid_token_with_item_wrappers— token signed by a different key → 401Test plan
hatch run linting:all— passeshatch run testing:test tests/toolkit/test_ecdsa.py -v— 13/13 passedPOST /api/v0/price/{hash}/recalculatewith a valid token returns 200 and updatescost_creditfrom 0 to a non-zero value.Out of scope
verify_auth_token/verify_signatureto coerce inputs (kept strict — the contract is "primitives in, bool out").except Exception: return False(would have surfaced this as a 500 instead of 401, but is a bigger discussion)..valuedefensively elsewhere — onlyrequire_auth_tokenwas in scope here.