Skip to content

Return 400 or 404 instead of server errors for bad URLs

Tim Orling yocto-patches 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4layerindex/querysethelper.py: reject an invalid API filter or orderby with a 400layerindex/querysethelper.py tests/test_restapi.py+44 -40 replies
2/4layerindex/querysethelper.py: apply the API "orderby" parameterlayerindex/querysethelper.py tests/test_restapi.py+53 -40 replies
3/4layerindex: give a 404 for a non-numeric id in a URLlayerindex/urls.py layerindex/views.py tests/test_nonnumeric_ids.py+77 -240 replies
4/4layerindex/middleware.py: reject NUL characters in the URL with a 400docker/settings.py layerindex/middleware.py settings.py +1 more+67 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [layerindex-web][PATCH 0/4] Return 400 or 404 instead of server errors for bad URLs

Fuzzing the URLs of a test instance loaded with a copy of the production database found about 160 requests per pass that gave a 500 and about 350 that gave a 502, from a handful of causes. These fix four of them.

1: Bug 16517: an unknown field in an API "filter" or "orderby" raised a
bare BaseException, which killed the worker; a value of the wrong type, such as filter=id:abc, raised ValueError. Both are now a 400. In Piotr Buliński's analysis of the production access logs from July to November, 909 of the 912 API server errors were malformed filters.
2: Bug 16518: the API never applied "orderby" at all.
3: Bug 16519: a non-numeric id in a URL, or in branch_comparison's
from_branch and to_branch, gave a 500; it is now a 404.
4: Bug 16520: a NUL character in the URL gave a 500 on PostgreSQL. It is
now a 400 on every database.

With these, the fuzz runs give no 500s on PostgreSQL and one on MariaDB, the 4-byte emoji case of bug 16507, which these don't address. The 502s that remain are 5000-character URLs, which uWSGI rejects with its default 4 KB buffer; gunicorn returns a 400 for them.

Each fix comes with tests that fail without it. This applies on master-next, where "layerindex: add an RSS feed of recently published layers" changed the neighbouring line of layerindex/urls.py.

Tim Orling (4):
layerindex/querysethelper.py: reject an invalid API filter or orderby

    with a 400

layerindex/querysethelper.py: apply the API "orderby" parameter
layerindex: give a 404 for a non-numeric id in a URL layerindex/middleware.py: reject NUL characters in the URL with a 400

 docker/settings.py            |  1 +
 layerindex/middleware.py      | 21 +++++++++++-
 layerindex/querysethelper.py  | 41 +++++++++++++++++++----
 layerindex/urls.py            | 18 +++++-----
 layerindex/views.py           | 32 +++++++++---------
 settings.py                   |  1 +
 tests/test_nonnumeric_ids.py  | 51 ++++++++++++++++++++++++++++
 tests/test_null_characters.py | 45 +++++++++++++++++++++++++
 tests/test_restapi.py         | 62 +++++++++++++++++++++++++++++++++++
 9 files changed, 240 insertions(+), 32 deletions(-)
 create mode 100644 tests/test_nonnumeric_ids.py
 create mode 100644 tests/test_null_characters.py
Signature · 1 line
2.56.1