Skip to content

fix(crossref): validate graphic DOI suffix characters - #14524

Merged
aryanorastar merged 1 commit into
BasedHardware:mainfrom
dvdphobia:codex/crossref-doi-links
Sep 22, 2026
Merged

aryanorastar merged 1 commit into
BasedHardware:mainfrom
dvdphobia:codex/crossref-doi-links

Conversation

@dvdphobia

@dvdphobia dvdphobia commented Sep 18, 2026 •

Copy link
Copy Markdown

What changed and why

Follow-up to #14523. The resolver normalization from #14606 correctly parses trusted doi.org URLs, but its DOI suffix grammar rejects registered identifiers containing reserved characters such as < and >, as well as encoded suffix characters such as &, ?, =, @, +, and %.

This rebased change keeps the hardened scheme, host, credential, port, and decode-once checks already on main, while accepting visible Unicode DOI suffix characters and legacy dotted registrant codes. It rejects whitespace, controls, format code points, unassigned characters, and non-ASCII prefix digits. The normalized DOI is still quoted with safe="", so reserved characters and traversal-like suffix text remain inside one Crossref API path segment.

This is complementary to #13979: that PR handles malformed Crossref response payloads and HTTP client pooling, while this PR covers DOI input compatibility at the request boundary.

Product invariants affected

none

How it was verified

  • python plugins/omi-crossref-app/test_doi_normalization.py — 26 passed.
  • python -m pytest plugins/omi-crossref-app -q --tb=short — 33 passed.
  • python -m compileall -q plugins/omi-crossref-app — passed.
  • git diff --check — no whitespace errors.
  • Live Crossref lookup of registered DOI 10.1002/1097-4636(200108)56:2<297::aid-jbm1098>3.0.co;2-s returned HTTP 200 and the expected work when the DOI was quoted as one path segment.

The full manifest preflight cannot resolve in this sparse checkout because unrelated manifest paths under backend, mobile, web, and desktop are absent. The selected hermetic Crossref command and the complete plugin suite pass directly.

Tests

plugins/omi-crossref-app/test_doi_normalization.py now covers encoded reserved suffix characters, exact-once decoding with a remaining literal percent escape, legacy dotted registrant codes, a real registered DOI containing angle brackets, visible Unicode suffixes, rejected control/format/unassigned code points, rejected non-ASCII prefix digits, repeated-dot suffixes, and the exact outbound quoted Crossref path.

Backend Hermetic Merge Gate

Out of scope: this change only touches the Crossref plugin and its existing hermetic DOI suite; it does not change backend, lockfile, workflow, or gate paths.

Failure class (fixes)

Failure-Class: FC-overstrict-identifier-grammar

New guards

No new check is added. The existing crossref-doi-normalization-tests manifest entry runs the extended behavioral suite and would catch the over-restrictive DOI grammar.

The research, implementation, and tests were prepared with Codex assistance on behalf of @dvdphobia.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified end to end — nice, tight fix. What I checked on head 547d059:

  • plugins/omi-crossref-app/main.py — the normalization in get_crossref_work is correct at the boundary: doi: prefix stripping; resolver parsing restricted to doi.org / dx.doi.org (case-insensitive netloc allowlist, so doi.org.evil.example-style lookalikes are rejected); query strings and fragments dropped by using only resolver.path; exactly one unquote, so %2523b decodes once to %23b while a literal % in a bare DOI stays literal. The stricter re.fullmatch(r"10\.\d+(?:\.\d+)*/\S+", …) also closes a gap in the old "/" in normalized check — arbitrary slash-bearing strings can no longer reach the Crossref path — and the .. guard now runs after decoding, so %2E%2E-encoded traversal is still caught. quote(normalized, safe="") keeps the outbound request injection-safe.
  • plugins/omi-crossref-app/test_doi.py — hermetic via httpx.MockTransport, and it pins the actual outbound request URL (not just the response shape), plus asserts invalid inputs never contact Crossref. Good coverage across hosts, schemes, encodings, and traversal.
  • scripts/run-plugin-crossref-tests.sh — follows the run-plugin-coingecko-tests.sh / run-plugin-mentor-session-auth-tests.sh pattern (uv-first, pinned deps matching the plugin's requirements.txt, loud failure). One non-blocking nit: sibling runners read python_version from backend/.python-version rather than hardcoding "3.11" — worth aligning next time this file is touched.
  • .github/checks-manifest.yaml — additive crossref-app-tests entry; id/command/triggers/lanes/reason match the shape of the existing entries.

Execution: ran the suite in a clean python:3.11 container with the PR-pinned deps — test_doi.py 14/14 passed — and drove scripts/run-plugin-crossref-tests.sh through its uv lane end to end (exit 0). Together with the pre-existing test_clean.py that matches the 18 tests reported in the description.

Leaving merge sign-off to a maintainer: the checks-manifest addition introduces a new CI-lane check (workflow-sensitive surface), and issue #14523 is a bounty proposal whose reward disposition needs a maintainer call. Neither blocks the code itself.

— Omi automated maintainer review


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior python labels Sep 18, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Confirmed old unnormalized DOI resolver-URL handling still on main (clean()/get_crossref_work unchanged). Fix correctly parses doi:/bare/doi.org+dx.doi.org resolver forms, decodes once, rejects unrelated hosts; thorough test suite, all required checks pass (remaining pending are unrelated mobile/desktop builds). 5/5.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Verified on 547d05911dd0.

Leaving this open as the keep vehicle (remaining hole: crossref DOI resolver URL normalize complementary vs #13979; CONFLICTING). Overlap is on .github/checks-manifest.yaml, plugins/omi-crossref-app/main.py, plugins/omi-crossref-app/test_doi.py, scripts/run-plugin-crossref-tests.sh. Complementary work is not a later-copy close.

Head is DIRTY / review APPROVED. kodjima APPROVE is not a merge. I am not merging until this is MERGEABLE and hosted checks are green.

@dvdphobia
dvdphobia force-pushed the codex/crossref-doi-links branch from 547d059 to 8bc6df3 Compare September 21, 2026 15:02
@dvdphobia dvdphobia changed the title fix(crossref): normalize DOI resolver URLs before lookup (#14523) fix(crossref): accept reserved DOI suffix characters Sep 21, 2026
@dvdphobia

Copy link
Copy Markdown
Author

@aryanorastar Rebased onto current main and resolved the Crossref overlap. Head is now 8bc6df389eaa; GitHub reports the PR mergeable.

The remaining delta keeps the hardened resolver parsing from #14606 and fixes its over-restrictive DOI suffix grammar. It includes a regression for a registered Crossref DOI containing angle brackets plus encoded reserved-character and exact-once-decoding coverage.

Local verification:

  • python plugins/omi-crossref-app/test_doi_normalization.py — 22 passed
  • full Crossref plugin suite — 29 passed
  • compileall and diff check — passed
  • live Crossref lookup of the registered angle-bracket DOI — HTTP 200

All fresh hosted workflow runs currently show action_required with zero jobs, so they need upstream approval before checks can execute. Please approve the fork workflow runs and re-review the rebased head when convenient.

@dvdphobia
dvdphobia requested a review from kodjima33 September 21, 2026 15:09

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed current head 8bc6df389eaa. origin/main _DOI_RE still rejects reserved DOI suffix characters ([-._;()/:A-Z0-9#]+). This SHA widens the suffix grammar and pins it. Hygiene SUCCESS. Not merging.

Accept registered Unicode graphic suffix characters while rejecting whitespace, controls, format code points, and non-ASCII prefix digits. Keep traversal-like suffix text safe by quoting the complete DOI as one outbound path segment.

Failure-Class: FC-overstrict-identifier-grammar
@dvdphobia
dvdphobia force-pushed the codex/crossref-doi-links branch from 8bc6df3 to 21bde74 Compare September 22, 2026 09:05
@dvdphobia dvdphobia changed the title fix(crossref): accept reserved DOI suffix characters fix(crossref): validate graphic DOI suffix characters Sep 22, 2026
@dvdphobia

Copy link
Copy Markdown
Author

@aryanorastar @kodjima33 Follow-up on current head 21bde747cdd: after the approval, a validator audit found that Python \S admitted NUL, DEL, zero-width format characters, and unassigned code points, while \d admitted non-ASCII prefix digits. I tightened the grammar to ASCII prefix digits plus visible Unicode letter/mark/number/punctuation/symbol suffix categories.

I also removed the .. substring ban: the whole DOI is quoted with safe="", and a boundary test proves 10.5555/a/../b is sent as /works/10.5555%2Fa%2F..%2Fb, so it cannot become a path traversal while valid punctuation remains accepted.

Verification on the new head:

  • DOI normalization suite: 26 passed
  • full Crossref plugin suite: 33 passed
  • compileall and diff check: passed

Please re-review after hosted checks complete.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

_DOI_RE on main still rejects graphic suffix characters, so the Wiley DOI fails normalize_doi. This head allowlists those characters and test_doi_normalization.py pins the Wiley DOI. Hygiene is green on 21bde747cddd.

@aryanorastar
aryanorastar merged commit 1ee3b31 into BasedHardware:main Sep 22, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

positive-signal Automation verified a genuine fix/quality contribution python workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants