Skip to content

fix: schema patterns accept a trailing newline #797

Closed

Description

@uniqueg

Problem

Connexion validates request parameters and bodies with jsonschema, which
checks pattern with Python's re.search(). In Python, $ also matches
before a newline at the end of the string, so a pattern like
^[0-9a-f]{24}$ accepts "<24 hex digits>\n". In ECMA 262 regular
expressions, which JSON Schema and OpenAPI refer to, $ only matches at the
end, so the API specification promises a stricter check than the app makes.

Controllers that rely on the pattern then get values they don't expect. For
example, a page token checked only by its pattern and then parsed as a
MongoDB ObjectId raises bson.errors.InvalidId, which apps without a
mapping for it answer with 500 Internal Server Error instead of 400.

Reproduce:

import jsonschema

schema = {"type": "string", "pattern": "^[0-9a-f]{24}$"}
jsonschema.Draft4Validator(schema).is_valid("a" * 24 + "\n")  # True

In a request: GET /objects?pageToken=aaaaaaaaaaaaaaaaaaaaaaaa%0A.

Proposal

Make FOCA's request validation check patterns as ECMA 262 does at the end of
the string, e.g., with a format checker or a validator that uses
re.search() on patterns whose $ is replaced by \Z (outside character
classes and escapes), or by refusing values with a trailing newline where the
pattern ends with $. Add a test with a trailing \n on a query parameter,
a path parameter and a body field.

Until then, apps check such values again in their controllers with
re.fullmatch() (drs-filer does so for pageToken in its PR for #59).
Apps with ^...$ patterns on parameters they parse further (page tokens,
identifiers) should be checked for the same gap.

Activity

  1. added
    priority: medium
    status: triage
    type: bug
    workload: hours
    on Nov 19, 2026
  2. added
    status: in progress
    and removed
    status: triage
    on Nov 20, 2026
  3. self-assigned this
    on Nov 20, 2026
  4. moved this from Backlog to In progress in ELIXIR On-Cloud: Low Priorityon Nov 20, 2026
  5. moved this from In progress to In review in ELIXIR On-Cloud: Low Priorityon Nov 21, 2026
  6. removed
    status: in progress
    on Nov 23, 2026
  7. added this to the v0.23.0 milestone on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: mediumtype: bugworkload: hours

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions