Bug 16517

Summary: layerindex: REST API returns 500, or kills the worker, for an invalid "filter" or "orderby" instead of 400
Product: [Yocto Project Subprojects] Layer Index Reporter: Tim Orling <tim.orling>
Component: Layer IndexAssignee: Tim Orling <tim.orling>
Status: NEW --- QA Contact: apoorv sangal <apoorvsangal>
Severity: normal    
Priority: Medium    
Version: 6.1   
Target Milestone: 6.2   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Tim Orling 2026-11-16 04:19:31 UTC
The REST API (layerindex/querysethelper.py) handles bad query parameters badly:

- A filter or orderby naming an unknown field, or with the wrong number of ":" separators, raises BaseException in get_search_tuple(). Django and the WSGI server don't catch BaseException: under uWSGI the worker dies and the client gets a 502, e.g.
    /layerindex/api/layerItems/?filter=pn:x
    /layerindex/api/layerItems/?orderby=%20
  The log shows: BaseException: Invalid filter ('pn', [...list of valid fields...])
- A value of the wrong type for the field raises ValueError and gives a 500, e.g.
    /layerindex/api/layerItems/?filter=id:abc
    ValueError: Field 'id' expected a number but got 'abc'.

Both should be a 400 with a short message (e.g. rest_framework.exceptions.ParseError or ValidationError). Found by fuzz testing a bench instance (layers.moto-timo.io); the same requests fail on MariaDB and PostgreSQL. A fuzz pass of the API gives several hundred of these.