You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: schema patterns accept a trailing newline #797
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.
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