oliver-zehentleitner / maity
clean-up: secrets and signing: one derived-id helper, keyword-only signing args, one instance pattern, safe_url in redact.py, a jcs compatibility path
tsk-53swp51q57tg Open
From the clean-up audit tsk-hgnbapyw7hnh, Area 1 (Secrets and signing), read at 80647565. Line numbers are at 80647565; check each one against current main before changing it. Finding numbers are the audit's (A1-n).
Small, low-risk items around ids, request signing and redaction. All S; they fit one or two PRs. The secretbox card for this area (tsk-xkwfxqp240kd) was filed at the same time.
1. chat_request builds an id from ids.py internals (A1-5, design)
chat_request.py:129-146(_request_id) importsids.CROCKFORDandids.PREFIXES(line 43) and assemblesreq-+ 12 Crockford characters from a sha256 by hand. It is the only deterministic id; ids.py has no helper for it.- Proposal:
ids.derived_id(entity, seed: bytes)in ids.py with the same mapping (CROCKFORD[b % 32]over the first 12 digest bytes), so ids.py stays the one place that knows the id shape. - Effort: S. Risk: low if the mapping stays byte-for-byte. A different mapping during a rolling deploy could let two replicas file two requests for one pair.
2. The CLI and the hub take On-Request and For in opposite positional order (A1-6, design)
cli/src/maity/sign.py:79-88canonical_string(..., body, on_request, for_member)andsign_headers(..., timestamp, on_request, for_member)(sign.py:98-107). The hub'sauth/credentials.py:85-94hascanonical_string(..., body, for_member, on_request). Both are called positionally:cli/src/maity/hub.py:593,cli/tests/test_bridge_for.py:25-28,hub/tests/test_bridge_calls.py:89-90, 107-108.- The line order inside the string is correct on both sides (§2.2: On-Request, then
for:), but a caller or test copied from one side to the other silently swaps the two lines. - Proposal: make
on_requestandfor_memberkeyword-only on both sides (*, on_request=None, for_member=None), in the same order. - Effort: S. Risk: low (signature only; tests pin the strings).
3. The instance-id pattern is written out twice in the hub (A1-7, duplication)
ids.py:65-75owns the alphabet (INSTANCE_ALPHABET). The pattern[2-9a-hjkmnp-z]{4,5}is spelled out again atinstances.py:29(INSTANCE_PATTERN) andmentions.py:38(_SUFFIX), and as a comment attables.py:57. The CLI copy (cli/src/maity/cli.py:596) is cross-package and expected.- Proposal: one pattern next to the alphabet in ids.py (or
instances.INSTANCE_PATTERN); mentions builds_SUFFIXfrom it. - Effort: S. Risk: low (check for an import cycle between mentions and instances).
4. The CLI has two URL redactors with different rules (A1-8, design)
cli/src/maity/redact.py:17-22without_userinfois the §13 helper (cli/context/credentials.md:435calls it "one helper").cli/src/maity/hub.py:115-124safe_urlis a second redactor: it drops userinfo and the query but keeps the path. It is used in 8+ places (hub.py:106, 136-142, 164, 190, 347, 350, 380, 408; runner/commands.py:98, 509; runner/serve.py:287, 348).- Proposal: move
safe_urlinto redact.py next towithout_userinfo, so everything that keeps credentials out of what maity prints lives in one module, and state the rule for path and query once. - Effort: S. Risk: low (a move plus imports).
5. A compatibility path in the foreign-agent consent view (A1-9, debt; closest caller of jcs.py)
foreign_agent.py:546-561(_agent_change): when a stored proposal has nocanonical/sha256, it rebuildspresentfromvaluesand recomputes_hash(proposed). The only writer,file()(foreign_agent.py:338-356), always stores both for every shown field, so the fallback only serves proposals stored before those fields existed. The alpha has no legacy users. The recomputation can also raiseCanonicalErroron a read.- Proposal: read
proposal["canonical"]/proposal["sha256"]directly and delete the fallback branches. - Effort: S. Risk: low (in the alpha, a row older than the field needs a reset anyway).
Order
- Item 4 after tsk-qtr9myhtysbs (in progress), whose item 3 changes
safe_urlitself. Move it after that lands. - Item 2: tsk-bg5f4cv0894w and tsk-d9r02hn5n32y also edit
auth/credentials.py; rebase rather than conflict. - The rest is independent.
Covered elsewhere
- None of these five. Searched:
_request_id,chat_request,canonical_string,INSTANCE_PATTERN,safe_url,_agent_change. Onlysafe_urlhas a card (tsk-qtr9myhtysbs), for a different change.
Effort sum: 5S.