//nefariousplan

CVE-2026-46645: SQLAdmin's Prior Fix Added One of Two Rails. The CVE Names the Other.

vendor

pattern

cve

proof of concept

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.

Six routes carried two rails

SQLAdmin'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.

@login_required
async def list(self, request: Request) -> Response:
    """List route to display paginated Model instances."""

    await self._list(request)

    model_view = self._find_model_view(request.path_params["identity"])
    pagination = await model_view.list(request)
    pagination.add_pagination_urls(request.url)
    ...

The @login_required decorator authenticates the caller. The await self._list(request) call on the next line is the authorization rail. _list does one thing:

async def _list(self, request: Request) -> None:
    model_view = self._find_model_view(request.path_params["identity"])
    if not model_view.is_accessible(request):
        raise HTTPException(status_code=403)

The 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.

That 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.

ajax_lookup is the seventh route in the same dispatch table. In 0.25.0 it carries neither rail.

async def ajax_lookup(self, request: Request) -> Response:
    """Ajax lookup route."""

    identity = request.path_params["identity"]
    model_view = self._find_model_view(identity)

    name = request.query_params.get("name")
    term = request.query_params.get("term")

    if not name or not term:
        raise HTTPException(status_code=400)

    try:
        loader: QueryAjaxModelLoader = model_view._form_ajax_refs[name]
    except KeyError as exc:
        raise HTTPException(status_code=400) from exc

    data = [loader.format(m) for m in await loader.get_list(term)]
    return JSONResponse({"results": data})

No 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.

CVE-2026-46645 names what happens next.

The exploit primitive

The 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.

A reproduction lab published by rootdirective-sec defines a ReportAdmin view restricted by is_accessible:

class ReportAdmin(ModelView, model=Report):
    form_ajax_refs = {
        "project": {
            "fields": ("name",),
            "order_by": "name",
            "limit": 10,
        }
    }

    def is_accessible(self, request: Request) -> bool:
        return False

The 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.

The exploit on 0.25.0 is one request, after authenticating as any user the application's AuthenticationBackend accepts:

curl -i -s -b "$COOKIE_JAR" \
  "$TARGET/admin/report/ajax/lookup?name=project&term=Secret"

Response:

HTTP/1.1 200 OK
content-type: application/json

{
  "results": [
    {"id": "1", "text": "Secret Project Alpha"},
    {"id": "2", "text": "Secret Project Beta"}
  ]
}

ReportAdmin.is_accessible(request) returned False. The endpoint returned the relationship targets anyway. On 0.25.1 the same request returns 403.

The 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.

Issue #1011 named the first rail

GitHub user vsemionov opened issue #1011 on 2026-03-03 against the public aminalaee/sqladmin repository. Title: "AJAX endpoint is not authenticated." Body:

The AJAX lookup endpoint at /{identity}/ajax/lookup lacks authentication requirements. This allows unauthorized users to access data through requests like:

http://localhost:8000/admin/membership/ajax/lookup?name=user&term=test

The 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.

The 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.

SQLAdmin 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.

PR #1035 added the rail the reporter named

Eleven 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:

Fixes #1011. The /{identity}/ajax/lookup endpoint was publicly accessible without any authentication, allowing unauthenticated users to query model data directly.

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.

The diff to sqladmin/application.py was four inline lines, added inside ajax_lookup after the docstring:

if self.authentication_backend is not None:
    authenticated = await self.authentication_backend.authenticate(request)
    if not authenticated or isinstance(authenticated, Response):
        return RedirectResponse(request.url_for("admin:login"), status_code=302)

The 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.

The PR description said "consistent with how other protected endpoints are handled." The other protected endpoints handle authentication and authorization. The patch handled authentication.

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.

The 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.

The second rail arrived through the security advisory channel

Between 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."

"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.

That fourth commit made the changes the lab and the 0.25.1 release notes describe:

+    @login_required
     async def ajax_lookup(self, request: Request) -> Response:
         """Ajax lookup route."""

-        if self.authentication_backend is not None:
-            authenticated = await self.authentication_backend.authenticate(request)
-            if not authenticated or isinstance(authenticated, Response):
-                return RedirectResponse(request.url_for("admin:login"), status_code=302)
-
         identity = request.path_params["identity"]
         model_view = self._find_model_view(identity)

+        if not model_view.is_accessible(request):
+            raise HTTPException(status_code=403)
+
         name = request.query_params.get("name")
         term = request.query_params.get("term")

The 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.

CVE-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.

What 0.25.1 did not restore

The 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.

The patch closes the CVE. It does not restore the convention.

That 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._<name>(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.

The pattern

This is the 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, and JeecgBoot's mLogin method written as a sibling of login without the captcha check. 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.

The 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.

PoC: rootdirective-sec/CVE-2026-46645-Analysis-Lab

Half the convention shipped as a public PR. The other half shipped as a CVE.