-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## Six routes carried two rails\n\nSQLAdmin's `Admin` class in `sqladmin/application.py` registers six public model-view routes: `list`, `details`, `create`, `edit`, `delete`, `export`. In 0.25.0 every one of them follows the same two-line dispatch shape.\n\n```python\n@login_required\nasync def list(self, request: Request) -> Response:\n \"\"\"List route to display paginated Model instances.\"\"\"\n\n await self._list(request)\n\n model_view = self._find_model_view(request.path_params[\"identity\"])\n pagination = await model_view.list(request)\n pagination.add_pagination_urls(request.url)\n ...\n```\n\nThe `@login_required` decorator authenticates the caller. The `await self._list(request)` call on the next line is the authorization rail. `_list` does one thing:\n\n```python\nasync def _list(self, request: Request) -> None:\n model_view = self._find_model_view(request.path_params[\"identity\"])\n if not model_view.is_accessible(request):\n raise HTTPException(status_code=403)\n```\n\nThe same shape repeats five more times. `_details` adds `can_view_details`. `_create` adds `can_create`. `_delete` adds `can_delete`. `_edit` adds `can_edit`. `_export` adds `can_export`. Every one of them calls `is_accessible(request)` first and raises 403 if the answer is no.\n\nThat convention is the dispatcher's security model. Every public admin route in SQLAdmin authenticates the caller with `@login_required`, then asks the target `ModelView` whether the request is permitted, then runs.\n\n`ajax_lookup` is the seventh route in the same dispatch table. In 0.25.0 it carries neither rail.\n\n```python\nasync def ajax_lookup(self, request: Request) -> Response:\n \"\"\"Ajax lookup route.\"\"\"\n\n identity = request.path_params[\"identity\"]\n model_view = self._find_model_view(identity)\n\n name = request.query_params.get(\"name\")\n term = request.query_params.get(\"term\")\n\n if not name or not term:\n raise HTTPException(status_code=400)\n\n try:\n loader: QueryAjaxModelLoader = model_view._form_ajax_refs[name]\n except KeyError as exc:\n raise HTTPException(status_code=400) from exc\n\n data = [loader.format(m) for m in await loader.get_list(term)]\n return JSONResponse({\"results\": data})\n```\n\nNo decorator. No `_ajax_lookup` helper. No call to `is_accessible`. The route resolves the target `ModelView` from the URL identity, reads the `form_ajax_refs` loader for the named relationship field, and returns JSON results.\n\nCVE-2026-46645 names what happens next.\n\n## The exploit primitive\n\nThe GHSA-54mc-gghv-4cfj advisory calls this an \"authorization bypass on `ajax_lookup`,\" which is the half of the bug the CVE numbers. The other half, the absent authentication, was numbered separately as issue #1011 and fixed as PR #1035.\n\nA reproduction lab published by rootdirective-sec defines a `ReportAdmin` view restricted by `is_accessible`:\n\n```python\nclass ReportAdmin(ModelView, model=Report):\n form_ajax_refs = {\n \"project\": {\n \"fields\": (\"name\",),\n \"order_by\": \"name\",\n \"limit\": 10,\n }\n }\n\n def is_accessible(self, request: Request) -> bool:\n return False\n```\n\nThe application also defines a `SecretProject` model joined to `Report` through a relationship. The `form_ajax_refs` declaration above tells SQLAdmin to register an AJAX lookup endpoint at `/admin/report/ajax/lookup` for the `project` field. That endpoint exists whether or not `ReportAdmin.is_accessible(request)` returns true. In 0.25.0 the endpoint runs whether or not `is_accessible(request)` returns true.\n\nThe exploit on 0.25.0 is one request, after authenticating as any user the application's `AuthenticationBackend` accepts:\n\n```bash\ncurl -i -s -b \"$COOKIE_JAR\" \\\n \"$TARGET/admin/report/ajax/lookup?name=project&term=Secret\"\n```\n\nResponse:\n\n```http\nHTTP/1.1 200 OK\ncontent-type: application/json\n\n{\n \"results\": [\n {\"id\": \"1\", \"text\": \"Secret Project Alpha\"},\n {\"id\": \"2\", \"text\": \"Secret Project Beta\"}\n ]\n}\n```\n\n`ReportAdmin.is_accessible(request)` returned `False`. The endpoint returned the relationship targets anyway. On 0.25.1 the same request returns 403.\n\nThe same `curl` without the cookie also returns 200 on 0.25.0. The decorator the other six routes carry is the same decorator `ajax_lookup` doesn't carry. Two rails missing as a pair.\n\n## Issue #1011 named the first rail\n\nGitHub user `vsemionov` opened issue #1011 on 2026-03-03 against the public `aminalaee/sqladmin` repository. Title: \"AJAX endpoint is not authenticated.\" Body:\n\n> The AJAX lookup endpoint at `/{identity}/ajax/lookup` lacks authentication requirements. This allows unauthorized users to access data through requests like:\n>\n> `http://localhost:8000/admin/membership/ajax/lookup?name=user&term=test`\n\nThe reporter named the authentication gap. They proposed a workaround that wrapped the endpoint in their custom `Admin` subclass with `login_required`. They noted the decorator was not designed for AJAX requests and that the workaround was a stopgap.\n\nThe issue was labeled \"bug.\" Not \"security.\" Not \"advisory.\" Public to the world from the moment it was filed. SQLAdmin's unauthenticated lookup endpoint was on the record from 2026-03-03 onward.\n\nSQLAdmin 0.25.0 was tagged on 2026-04-18, forty-six days later. The 0.25.0 release notes list new template hooks, toast notifications for custom actions, primary-action availability checks on listing pages, and improved error handling during deletion. They do not mention `ajax_lookup`. The 0.25.0 release shipped without addressing issue #1011.\n\n## PR #1035 added the rail the reporter named\n\nEleven days after 0.25.0 shipped, `vahidzhe` opened pull request #1035 against the same public repo. PR title: \"fix: authenticate ajax lookup endpoint.\" Description, verbatim:\n\n> Fixes #1011. The `/{identity}/ajax/lookup` endpoint was publicly accessible without any authentication, allowing unauthenticated users to query model data directly.\n>\n> Added authentication check at the start of `ajax_lookup()`, consistent with how other protected endpoints are handled. Unauthenticated requests are redirected to the login page.\n\nThe diff to `sqladmin/application.py` was four inline lines, added inside `ajax_lookup` after the docstring:\n\n```python\nif self.authentication_backend is not None:\n authenticated = await self.authentication_backend.authenticate(request)\n if not authenticated or isinstance(authenticated, Response):\n return RedirectResponse(request.url_for(\"admin:login\"), status_code=302)\n```\n\nThe four lines inline the work `@login_required` would do as a decorator. The reviewer was `aminalaee`, the project owner. The approval comment, verbatim: \"Implementation looks good to me 👍.\" The PR merged 2026-04-29 as commit `b0d3a19`.\n\nThe PR description said \"consistent with how other protected endpoints are handled.\" The other protected endpoints handle authentication and authorization. The patch handled authentication.\n\n`list`, `details`, `create`, `edit`, `delete`, and `export` each carry `@login_required` and call an underscore-prefixed helper that raises 403 when `is_accessible(request)` returns false. PR #1035 added the inline equivalent of the decorator. It did not add a call to a helper, and it did not add an `is_accessible` check inline. The PR description named the convention. The patch implemented one of its two rails.\n\nThe reporter who filed #1011 named the authentication gap. The contributor who wrote #1035 closed the gap the reporter named. The reviewer who approved #1035 read the patch as consistent with the dispatch convention. Three pairs of eyes, one rail.\n\n## The second rail arrived through the security advisory channel\n\nBetween PR #1035 merging on April 29 and SQLAdmin 0.25.1 tagging on May 16, four commits landed on the main branch. Two were Dependabot bumps. One was the 0.25.1 version commit. The fourth, dated 2026-05-16 at 11:51 UTC, has author \"Amin Alaee\" and message \"Merge commit from fork.\"\n\n\"Merge commit from fork\" is the default message GitHub generates when a maintainer accepts a fix through the Security Advisory private-fork workflow. The advisory is filed privately. GitHub creates a private fork. The fixing commit lands on that fork. The maintainer merges the fork into main and tags a release the same day. The commit message is whatever the author leaves it as. \"Merge commit from fork\" is what it stays as when the author leaves it as the default.\n\nThat fourth commit made the changes the lab and the 0.25.1 release notes describe:\n\n```diff\n+ @login_required\n async def ajax_lookup(self, request: Request) -> Response:\n \"\"\"Ajax lookup route.\"\"\"\n\n- if self.authentication_backend is not None:\n- authenticated = await self.authentication_backend.authenticate(request)\n- if not authenticated or isinstance(authenticated, Response):\n- return RedirectResponse(request.url_for(\"admin:login\"), status_code=302)\n-\n identity = request.path_params[\"identity\"]\n model_view = self._find_model_view(identity)\n\n+ if not model_view.is_accessible(request):\n+ raise HTTPException(status_code=403)\n+\n name = request.query_params.get(\"name\")\n term = request.query_params.get(\"term\")\n```\n\nThe four inline authentication lines PR #1035 added were deleted. The `@login_required` decorator the other six routes carry was added. The `is_accessible` check the other six routes perform inside their `_list` / `_details` helpers was added inline.\n\nCVE-2026-46645 covers the new `is_accessible` lines. The decorator was already on the record as the public fix for issue #1011. The authentication rail was a publicly-known gap closed by a publicly-reviewed PR. The authorization rail was a privately-disclosed gap closed by a coordinated security advisory. Same handler, two rails, two disclosure tracks, two CVE-or-not outcomes.\n\n## What 0.25.1 did not restore\n\nThe patched `ajax_lookup` in 0.25.1 carries `@login_required` and an inline `is_accessible` check. The other six routes carry `@login_required` and call `await self._list(request)` (or `_details`, `_create`, etc.) where the underscore-prefixed helper centralizes the access decision. There is no `_ajax_lookup` helper in 0.25.1. The patched route is a third dispatch shape: decorator like the other six, but authorization check inlined instead of delegated to a helper that does not exist.\n\nThe patch closes the CVE. It does not restore the convention.\n\nThat distinction matters because the convention was the security model. Six helpers, all calling `is_accessible` from the same location, are a single point of audit. Six handlers that each call their own helper are a registration discipline a reviewer can grep for: every route in `Admin` should `await self._(request)` near the top. The `ajax_lookup` route in 0.25.0 was missing from that registration. The `ajax_lookup` route in 0.25.1 is still missing from it. The next time a contributor adds an eighth route to the same dispatch by looking at existing routes for reference, the example they copy from will be the one the maintainers wrote after the CVE was already in flight.\n\n## The pattern\n\nThis is the [parallel implementation gap](/patterns/parallel-implementation-gap). The same shape has produced 38 prior exhibits, including [Astro's `/_image` endpoint where the Cloudflare adapter never imported the allowlist the canonical handler used](/posts/astro-shipped-two-image-endpoints), and [JeecgBoot's `mLogin` method written as a sibling of `login` without the captcha check](/posts/jeecgboot-mlogin-validatecaptcha-sibling-method). SQLAdmin's seven admin routes are seven implementations of \"an HTTP entry point that resolves an identity to a `ModelView`, asks the view whether the request is allowed, and runs the action.\" Six of them were written together and share a helper. The seventh was added separately, for a separate consumer, by an author who solved the problem the Select2 widget needed solving and did not import the security rails that lived nowhere except in the other six handlers' source.\n\nThe dispatch in `Admin` has no class-level pre-handler. No `before_request`. No router middleware that catches missed routes. The convention is the only mechanism, and the convention is documentation enforced by the attention of whoever writes the next handler. `ajax_lookup` got written without that attention. PR #1035 got written without it. The reviewer who approved PR #1035 was reading for consistency with the authentication rail and not for consistency with the authorization rail, because the authorization rail in the convention lives inside a helper that does not appear at the call site, and the reporter who filed #1011 did not name it.\n\nPoC: [rootdirective-sec/CVE-2026-46645-Analysis-Lab](https://github.com/rootdirective-sec/CVE-2026-46645-Analysis-Lab)","closing_line":"Half the convention shipped as a public PR. The other half shipped as a CVE.","hook_md":"SQLAdmin's admin dispatch carries two security rails. `@login_required` authenticates the caller. A per-action helper, `_list` for the list route, `_details` for the details route, calls `is_accessible(request)` and returns 403 if the answer is no. Six routes in SQLAdmin's `Admin` class follow that two-rail pattern. `ajax_lookup` was the seventh. In 0.25.0 it carried neither rail. PR #1035 added the first one in April 2026 and described the fix as \"consistent with how other protected endpoints are handled.\" CVE-2026-46645 is the second one.","post_id":612,"slug":"sqladmin-cve-2026-46645-prior-fix-added-one-rail","title":"CVE-2026-46645: SQLAdmin's Prior Fix Added One of Two Rails. The CVE Names the Other.","type":"initial","unreadable_sentence":"PR #1035's description said \"consistent with how other protected endpoints are handled.\" Six other endpoints carry two rails. The patch added one."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCas/VJAAKCRDeZjl4jgkQ Jt9QAP90rUWT6kIjdRqDbMB23q0hP92/+uNQMSAs91FTRntgbwEAkZIZV2UVwsJt T2OZn3y4IhnozFYSxwvrpCv5u+GBuAs= =iVg9 -----END PGP SIGNATURE-----