mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #22942] [CLOSED] fix: resolve unhandled 500 error on unauthenticated api requests #65794
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/22942
Author: @brenmor24
Created: 3/23/2026
Status: ❌ Closed
Base:
dev← Head:unauthorized-request-handling-support📝 Commits (1)
901c4b2fix: resolve 500 error on unauthenticated api requests📊 Changes
1 file changed (+19 additions, -0 deletions)
View changed files
📝
src/routes/+layout.svelte(+19 -0)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch. PRs targetingmainwill be immediately closed.devto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.Changelog Entry
Description
This PR resolves the problems outlined in issue #21072 where users sometimes encounter error pages with messages such as "500: Internal Error" or "Open WebUI Backend Required". This happens when using authenticating reverse-proxies which is required for trusted header authentication. As described in the issue, unauthenticated background API requests are redirected to the identity provider for re-authentication, but they're blocked by the browser since this violates CORS policy. This behavior is expected, and redirecting background requests should probably not be supported
Ideally the browser would refresh the user's session token before it expires by reaching out to the identity provider, but there is currently no support for this in Open WebUI. If a refresh doesn't happen in time, it is generally best to deny background API requests by returning a 401 after a user session has expired and let the frontend decide what to do. Open WebUI doesn't handle this case either which results in the same issues that come from CORS violations. This PR implements a fix to handle these cases where 401s occur
Fixed
+layout.sveltein this PR in order to catch unauthenticated background requests and trigger re-authentication. This is done by catching all 401s returned from internal requests to API paths ("/api/", "/ollama/", "/openai/", "/ws/"). Once caught, the current page is reloaded. This triggers a top-level request allowing redirection to the identity provider which does not violate CORS policy. So the reverse-proxy would need to be configured to deny unauthenticated requests on API paths and redirect unauthenticated requests on all other pathsAdditional Information
This fix can be observed by running an openresty nginx reverse-proxy locally using the docker compose and nginx config below. Headers required for trusted header authentication are attached in this nginx container. Requests to API paths are rejected when the reverse-proxy is in an "unauthenticated" state which is reached 15 seconds after the previous 401 was fired. This is to simulate token expiry with a short enough window for observation. This setup is used in the before/after videos in the screenshot/video section
docker-compose.ymlnginx.confThe following changes need to be made in the dev environment to support the reverse-proxy setup described above:
vite.config.ts.envsrc/lib/constants.tsbackend/dev.shScreenshots or Videos
The videos below demonstrate how the frontend behaves with the reverse-proxy setup described above before and after adding a handler to
+layout.svelte. In both videos, there's an attempt to navigate to "Workspace". This causes stalling with a loading spinner before the fix, but re-authentication is observed after the fix. An attempt is also made to reload the page in the first video which results in the "Open WebUI Backend Required" page due to a failed background request to /api/config as observed in the originally reported issue. This again triggers re-authentication which resolves the problem as shown in the second videoBefore fix:
https://github.com/user-attachments/assets/e4ad3412-638b-4d25-a55a-00ae2798b187
After fix:
https://github.com/user-attachments/assets/2a1b9400-a8a7-4749-a1b3-5cc2c42489c6
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.