Bug 16519

Summary: layerindex: non-numeric ids in URLs and branch_comparison parameters give 500 instead of 404
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:33 UTC
Several URL patterns in layerindex/urls.py capture the primary key with [-\w]+, which matches any word, and the views pass it to the id field, so a non-numeric value raises ValueError and gives a 500:

    /layerindex/recipe/NaN/
    /layerindex/recipe/_/
    /layerindex/oe-classic/recipe/x/
    /layerindex/comparison/recipe/x/
    ValueError: Field 'id' expected a number but got 'NaN'.

The from_branch and to_branch query parameters of /layerindex/branch_comparison/ (and _plain, _rst) have the same problem through get_object_or_404(Branch, id=...):

    /layerindex/branch_comparison/?from_branch=&to_branch=1
    ValueError: Field 'id' expected a number but got ''.

The URL patterns should use <int:pk> (or \d+) so these are a 404, and the branch parameters should be validated (404 or 400). Found by fuzz testing a bench instance; the same on MariaDB and PostgreSQL.