Skip to content

pathToSlug is not injective: an endpoint whose URL contains a hyphen is addressed as a different endpoint #123

Closed

Description

@jrosskopf

What

PathUtils::pathToSlug replaces every internal / with -, and slugToPath replaces every - with /. The codec is therefore lossy: a path containing a literal hyphen is indistinguishable from the same path containing a slash.

Measured against the real implementation:

"/customers/"    -> "customers-slash" -> "/customers/"
"/publicis"      -> "publicis"        -> "/publicis"
"/sap/functions" -> "sap-functions"   -> "/sap/functions"
"/a-b"           -> "a-b"             -> "/a/b"     <-- corrupted
"/a/b"           -> "a-b"             -> "/a/b"     <-- collides with the above

Why it matters

EndpointConfig::getSlug() is how the config service addresses endpoints: GET/PUT/DELETE /api/v1/_config/endpoints/{slug} and the four template-by-slug handlers. So for an endpoint at /order-items:

  • it is addressed by the same slug as an endpoint at /order/items, and
  • a round-trip through the config API rewrites its path to /order/items.

Hyphens in REST paths are entirely ordinary, so this is reachable with a plain config.

Why it is not fixed in passing

Any fix changes the /api/v1/_config/endpoints/{slug} URL for affected endpoints — an observable API surface change, not a refactor. It needs a decision on migration (escape scheme, versioned slug, or percent-encoding the path outright) rather than a quiet correction.

Found during an architecture review. The doc comment in path_utils.hpp also claimed "/sap/functions" -> "sap-slash-functions", which the code has never done; that comment has been corrected to the measured behaviour and points here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions