Skip to content

/query/{ledger} parses the path ledger once but authorizes, loads and compares its raw spelling #1982

Closed

Description

@bplatz

The ledger-scoped query route parses its {ledger} path segment once, into PathLedger (fluree-db-server/src/routes/query.rs), which holds both the canonical LedgerId and the path's raw spelling. Only the pin and the JSON-LD pin rewrite use the canonical id. The bearer scope check, the loaders and the two "Ledger mismatch" checks all take the raw spelling, and those don't agree with each other:

  • The scope check (scope_id, i.e. LedgerRef::parse(raw)?.id) accepts urn:fluree: and the bare-name form.
  • The loader (LedgerId::parse) rejects urn:fluree:.
  • The mismatch checks compare raw strings. normalize_ledger_scoped_from and ledger_scoped_sparql_dataset_spec use base_ledger_id / split_time_travel_suffix, which strip time and fragment but add no default branch. Explain compares typed ids and doesn't have this problem.

Repro (on main after #1958)

POST /v1/fluree/query/pinned          SPARQL: ... FROM <pinned:main> ...
-> 400 "Ledger mismatch: endpoint ledger is 'pinned' but SPARQL FROM targets 'pinned:main'"

POST /v1/fluree/query/urn:fluree:pinned:main
-> 400 "Invalid ledger id 'urn:fluree:pinned:main': branch cannot contain ':'"
   (the scope check accepted it as pinned:main)

The first refuses a valid request. The second fails closed, but the id that was authorized and the id that gets loaded come from different parsers.

Fix

Use the canonical id downstream (PathLedger.id instead of PathLedger.ledger) and switch the two mismatch checks to typed-id comparisons. Both are needed:

  • Changing the id alone breaks /query/mydb with a body from: "mydb" or FROM <mydb>, which works today. The path would become mydb:main while the body stays mydb.
  • Changing the comparisons alone leaves the urn:fluree: path refused.

The unit test for PathLedger::parse that currently checks the raw spelling needs updating with it.

Related: #1961 is the same problem in fluree-db-api (graph() vs db()). Found in review of #1970, MEDIUM-3.

Activity

  1. added
    P3
    area:server
    on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:server

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions