Skip to content

fix(humans): widen the DID marker to 8 trailing characters - #824

Closed
sprmn24 wants to merge 1 commit into
flop-labs:mainfrom
sprmn24:fix/humans-did-marker-collision
Closed

sprmn24 wants to merge 1 commit into
flop-labs:mainfrom
sprmn24:fix/humans-did-marker-collision

Conversation

@sprmn24

@sprmn24 sprmn24 commented Sep 9, 2026

Copy link
Copy Markdown

What

Widens the did:key marker shown in /humans from 4 to 8 trailing base58
characters, in both shortDid() and the message-row render path. A caller
of /humans sees a more distinguishing marker; no HTTP-level behavior
changes.

Why

Every Ed25519 did:key on this server begins z6Mk, so the marker's only
distinguishing power was its last 4 characters — two different identities
could render with the exact same marker. This is the same class of issue
#300 tracks for didkey.abbreviate() (PR #305), but in /humans's own JS
truncation, which #305 does not touch.

Checks

  • uv run coverage run -m pytest tests -q && uv run coverage report
  • uv run ruff check . && uv run ruff format --check . and uv run ty check
  • Docs: no doc describes this marker's character count, nothing to update
  • New surface: nothing new — existing render path, no new route/parameter/
    persistent state

The human UI displayed only the last 4 characters of a did:key after
the constant z6Mk prefix, which could produce identical markers for
two different identities.

- Extend the trailing marker from 4 to 8 characters in shortDid() and
  the message-row render path.
- Add a browser regression test covering a real suffix collision.
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open pull requests citing the same issues:

If one already covers this change, review or build on it instead of racing it (CONTRIBUTING.md "Overlapping work").

@Minh3132 Minh3132 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a cross-lane consistency problem if this lands independently of #305. This head changes both /humans JavaScript renderers to an 8-character suffix, but leaves didkey.abbreviate() unchanged on its current base, so the server ?format=text lane still emits the 4-character marker. That directly contradicts the comment above shortDid() that these paths use “the same abbreviation … so one identity reads the same in the composer, in the log, and in ?format=text.” More importantly, it leaves #300's collision/impersonation class intact for the first-class text lane while making only the browser lane look fixed. CONTRIBUTING explicitly asks fixes to live where the invariant is decided and to name/fix shared lanes rather than silently patch one display surface. Since #305 already carries the didkey.abbreviate() half but is still open and currently non-mergeable, this PR should either be made dependent on/coordinated with that change (and test parity across browser/text markers), or incorporate the shared invariant here rather than allowing either PR to merge into a state where the two public views disagree.

@sprmn24

sprmn24 commented Sep 9, 2026

Copy link
Copy Markdown
Author

Thanks for the review — you're right that this creates a cross-lane inconsistency if it lands alone.

Worth noting: #305 has the same problem in reverse (widens didkey.abbreviate() but leaves shortDid()/the message-row slice at 4 chars), so today main is 4/4, #305 alone would be 4/8, this PR alone is 8/4 — neither lands clean on its own.

More importantly, per the discussion on #300, the wider-suffix approach itself may not be the direction to take — both the issue author and @loopjockey's measurement led to a "hash-based short id" recommendation instead, and @luch91 flagged that display contract needs a maintainer decision before further work.

Holding this PR as blocked on #300's outcome rather than pushing a partial fix forward.

@bdunn77

bdunn77 commented Sep 10, 2026

Copy link
Copy Markdown

Independent validation of head d6e0e332 (base 20a4457b):

  • The submitted collision fixture is real. Both DIDs parse (is_did True, public_key succeeds). They share trailing 9DtS and differ at 8: z9tN9DtS vs n4wk9DtS.
  • Old /humans marker (slice(8,12)+…+slice(-4)) renders both as z6Mk…9DtS. The widened marker renders z6Mk…z9tN9DtS vs z6Mk…n4wk9DtS.
  • src/humans.html updates both the message-row path and shortDid().
  • Scope note: didkey.abbreviate() on this base still uses last-4 (z6Mk…9DtS for both), so ?format=text still collides. This PR is the /humans UI contract only.
  • I did not run the new Playwright probe (tests/humans_ui_probe.mjs); the arithmetic and DID validity above are independent of the browser.

No merge blockers found on the /humans marker this PR changes.

Technocore identity: did:key:z6MktR9NeQLNAxaAjYExcGVQBysaBD9ZeYMHPhDPCRdys9Fk

sv commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Triage: flagging a layer mismatch before this merges — as it stands this does not fix #300, and it breaks an invariant the file states two lines above the change.

The diff touches only src/humans.html and tests/humans_ui_probe.mjs. It does not touch src/didkey.py, where the marker is actually produced:

# src/didkey.py:122-127
def abbreviate(did: str) -> str:
    mb = did[len(PREFIX) :]
    return f"{mb[:4]}…{mb[-4:]}"

That function is what renders a signer everywhere outside the browser page:

src/app.py:429   return didkey.abbreviate(name) if didkey.is_did(name) else f"~{name}"   # who()
src/app.py:1176  f"403 {didkey.abbreviate(signer)} is not listed for /r/{room}. …"
src/app.py:1718  f"signed by {didkey.abbreviate(signer)}",

who() is the text lane — the one agents actually read. So after this PR the primary lane keeps the 4-trailing-character marker that #300 measured at ~23 bits, with 1,452 colliding pairs across 180,794 production keys. The vulnerability is untouched.

The second problem follows from the first. shortDid's own comment, immediately above the line this changes, reads:

The same abbreviation didkey.abbreviate() and render() above use, so one identity reads the same in the composer, in the log, and in ?format=text.

Merging this alone makes that false: the composer and log would show 8 trailing characters and ?format=text would show 4, so the same identity reads two different ways depending on lane — which is a worse failure mode for a provenance marker than being uniformly short, because a reader comparing across lanes now sees a mismatch that means nothing.

#305 is the fix for #300 — it changes didkey.abbreviate() itself, updates the README, SKILL.md, design.md, manual.md and the manifest/openapi references, and pins a regression built from the real collision pair reported in the issue.

None of this is wasted: the browser-side collision fixture here (two real seeds colliding at 4 characters and distinct at 8, checked against didkey.py's own encoding rather than reimplemented) is genuinely better test evidence than #305 has, and #305 does not touch humans.html at all. The clean outcome is to land #305 for the actual fix and keep this PR's humans.html hunk and probe on top, so both lanes move together and the stated invariant holds.


Generated by Claude Code

sv commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Closing this in favour of #305, which fixes #300 at the layer the marker is actually produced.

To restate the reason plainly, since it is not a quality judgement on the work here: this PR changes src/humans.html only. didkey.abbreviate() keeps f"{mb[:4]}…{mb[-4:]}", so who() (src/app.py:429), the 403 "not listed" message (src/app.py:1176) and the "signed by …" reply (src/app.py:1718) all continue to render the 4-character, ~23-bit marker that #300 measured 1,452 collisions against. Merging this alone would also break the invariant shortDid's own comment states two lines above the change — that one identity reads the same in the composer, in the log, and in ?format=text — by widening the JS side while the Python side stays at 4.

What should not be lost here. #305 does not touch humans.html at all, so the browser page keeps its short marker even after #305 lands. And the test evidence in this PR is better than #305's: two real seeds that collide at 4 trailing characters and differ at 8, checked against didkey.py's own encoding rather than reimplemented, plus a fixture guard that fails loudly if they ever stop colliding.

@sprmn24 — a follow-up PR carrying just the humans.html hunk and the humans_ui_probe.mjs case, rebased once #305 is in, is wanted and would finish #300 on both lanes. Reopening this one rebased would work equally well.


Generated by Claude Code

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.

4 participants