[PR #15035] [MERGED] fix: Resolve UnicodeEncodeError for non-ASCII usernames in forwarded headers #39324

Closed
opened 2026-04-25 11:57:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/15035
Author: @decent-engineer-decent-datascientist
Created: 6/16/2025
Status: Merged
Merged: 6/17/2025
Merged by: @tjbck

Base: devHead: dev


📝 Commits (2)

  • f7920df Fix non-ascii error issue on ENABLE_FORWARD_USER_INFO_HEADERS
  • 8a63a60 Fix typo on ollama patch

📊 Changes

5 files changed (+89 additions, -85 deletions)

View changed files

📝 backend/open_webui/retrieval/utils.py (+13 -12)
📝 backend/open_webui/routers/audio.py (+5 -4)
📝 backend/open_webui/routers/images.py (+5 -4)
📝 backend/open_webui/routers/ollama.py (+37 -36)
📝 backend/open_webui/routers/openai.py (+29 -29)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources? (Note: No documentation changes are required for this internal fix.)
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation? (Note: No new external dependencies are added; urllib is a standard Python library.)
  • Testing: Have you written and run sufficient tests to validate the changes? (Note: Validated by reproducing the original error with a non-ASCII username and confirming the fix resolves the UnicodeEncodeError during file uploads and other operations where headers are forwarded.)
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • fix: Bug fix or error correction

Changelog Entry

Description

This pull request fixes a UnicodeEncodeError that occurs when the ENABLE_FORWARD_USER_INFO_HEADERS setting is enabled for users with non-ASCII characters (e.g., Korean, Cyrillic) in their profile information.

The root cause was that user details were being placed directly into HTTP headers, which do not support non-Latin-1 characters. This change URL-encodes the values of the X-OpenWebUI-User-* headers to ensure they are safely transmitted, preventing the application from crashing during operations like file uploads or model interactions.

Added

  • N/A

Changed

  • All outgoing requests that forward user information (X-OpenWebUI-User-Name, X-OpenWebUI-User-Id, X-OpenWebUI-User-Email, X-OpenWebUI-User-Role) now have their values URL-encoded for safe HTTP transport.

Deprecated

  • N/A

Removed

  • N/A

Fixed

  • Fixes UnicodeEncodeError: 'latin-1' codec can't encode characters when ENABLE_FORWARD_USER_INFO_HEADERS is active for users with non-ASCII profile information.
  • Resolves failures in file uploads, embedding generation, and other backend services that rely on forwarding user-specific headers.

Security

  • Improves the robustness of data handling by correctly encoding user information, preventing unexpected server errors and crashes caused by unsupported characters.

Breaking Changes

  • N/A

Additional Information

Screenshots or Videos

  • N/A (This is a backend fix and has no visual component).

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/15035 **Author:** [@decent-engineer-decent-datascientist](https://github.com/decent-engineer-decent-datascientist) **Created:** 6/16/2025 **Status:** ✅ Merged **Merged:** 6/17/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `dev` --- ### 📝 Commits (2) - [`f7920df`](https://github.com/open-webui/open-webui/commit/f7920df8707af24d59a0c7a03266742743be2562) Fix non-ascii error issue on ENABLE_FORWARD_USER_INFO_HEADERS - [`8a63a60`](https://github.com/open-webui/open-webui/commit/8a63a601de7f07e9c75a85b125fe0375b3feb6e7) Fix typo on ollama patch ### 📊 Changes **5 files changed** (+89 additions, -85 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/retrieval/utils.py` (+13 -12) 📝 `backend/open_webui/routers/audio.py` (+5 -4) 📝 `backend/open_webui/routers/images.py` (+5 -4) 📝 `backend/open_webui/routers/ollama.py` (+37 -36) 📝 `backend/open_webui/routers/openai.py` (+29 -29) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [X] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? *(Note: No documentation changes are required for this internal fix.)* - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? *(Note: No new external dependencies are added; `urllib` is a standard Python library.)* - [x] **Testing:** Have you written and run sufficient tests to validate the changes? *(Note: Validated by reproducing the original error with a non-ASCII username and confirming the fix resolves the `UnicodeEncodeError` during file uploads and other operations where headers are forwarded.)* - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **fix**: Bug fix or error correction # Changelog Entry ### Description This pull request fixes a `UnicodeEncodeError` that occurs when the `ENABLE_FORWARD_USER_INFO_HEADERS` setting is enabled for users with non-ASCII characters (e.g., Korean, Cyrillic) in their profile information. The root cause was that user details were being placed directly into HTTP headers, which do not support non-Latin-1 characters. This change URL-encodes the values of the `X-OpenWebUI-User-*` headers to ensure they are safely transmitted, preventing the application from crashing during operations like file uploads or model interactions. ### Added - N/A ### Changed - All outgoing requests that forward user information (`X-OpenWebUI-User-Name`, `X-OpenWebUI-User-Id`, `X-OpenWebUI-User-Email`, `X-OpenWebUI-User-Role`) now have their values URL-encoded for safe HTTP transport. ### Deprecated - N/A ### Removed - N/A ### Fixed - Fixes `UnicodeEncodeError: 'latin-1' codec can't encode characters` when `ENABLE_FORWARD_USER_INFO_HEADERS` is active for users with non-ASCII profile information. - Resolves failures in file uploads, embedding generation, and other backend services that rely on forwarding user-specific headers. ### Security - Improves the robustness of data handling by correctly encoding user information, preventing unexpected server errors and crashes caused by unsupported characters. ### Breaking Changes - N/A --- ### Additional Information - This change directly implements the standard method for including non-ASCII characters in HTTP headers. - Should fix #14391 ### Screenshots or Videos - N/A (This is a backend fix and has no visual component). ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 11:57:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#39324