Skip to content

Python: Fix DevUI authentication for non-ASCII bearer tokens - #10354

Draft
Patel Namraa (Namraa310806) wants to merge 2 commits into
microsoft:mainfrom
Namraa310806:fix/devui-non-ascii-bearer-token
Draft

Patel Namraa (Namraa310806) wants to merge 2 commits into
microsoft:mainfrom
Namraa310806:fix/devui-non-ascii-bearer-token

Conversation

@Namraa310806

Copy link
Copy Markdown
Contributor

Motivation & Context

DevUI currently returns HTTP 500 when a non-ASCII bearer token is supplied because secrets.compare_digest() raises a TypeError when comparing non-ASCII strings.

This should be handled as an authentication mismatch rather than an internal server error.

This change proposes a consistent encoding contract for bearer-token authentication between the bundled frontend and the backend, while preserving existing ASCII-token behavior.

Description & Review Guide

  • What are the major changes?

    • Introduced byte-based bearer-token comparison using secrets.compare_digest() with Latin-1 encoding.
    • Restricted HTTP optional-whitespace trimming to spaces and tabs, preserving other valid token bytes.
    • Added a startup warning when a configured token contains characters outside the range supported by browser Fetch headers.
    • Added backend regression tests using httpx.ASGITransport to exercise exact header bytes.
    • Added an integration test that loads the actual ApiClient source through Vite, uses native fetch(), and communicates with a live Uvicorn-hosted DevUI server.
    • Documented the proposed token encoding behavior.
  • What is the impact of these changes?

    • ASCII bearer tokens continue to behave as before.
    • Latin-1-compatible tokens can be compared consistently across the frontend and backend.
    • Tokens containing characters above U+00FF are rejected safely rather than causing HTTP 500 responses.
    • Authentication comparison remains constant-time through secrets.compare_digest() on bytes.
  • What do you want reviewers to focus on?

    • Whether Latin-1 is the appropriate encoding contract for the bundled frontend and backend.
    • Whether rejecting tokens outside the Latin-1 range is the right behavior.
    • Whether the integration-test approach sufficiently exercises the actual frontend authentication path.
    • Whether the startup warning and documentation communicate the limitations clearly.

Related Issue

Related to #9713.

This is a draft implementation submitted to facilitate discussion of the proposed Latin-1 wire contract. Maintainer confirmation of the encoding approach is still pending. I would appreciate feedback on the contract before treating this PR as ready for review.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details:

AI assistance was used to help prepare and open the draft PR, refine and polish the PR description, discuss the implementation approach, review the code, identify and investigate edge cases, develop regression tests, and analyze test results. I independently reviewed the changes, verified the implementation, and ran the relevant validation checks. I understand the submitted changes and accept responsibility for them.

Contribution Checklist

  • The code builds clean without any errors or warnings.
  • All unit tests pass, and I have added new tests where possible.
  • The PR follows the Contribution Guidelines.
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change.

Validation performed:

  • DEVUI_WIRE_TEST=1 pytest test_bearer_auth_wire.py — 3 passed.
  • pytest test_server.py -k "bearer_token or token_matches" — 14 passed.
  • Ruff check and format check — clean.
  • Pyright — 0 errors.

Note: test_devui_streaming_renderer_memory_is_bounded also fails locally on unmodified main.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 02:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 14, 2026
@github-actions github-actions Bot changed the title Fix DevUI authentication for non-ASCII bearer tokens Python: Fix DevUI authentication for non-ASCII bearer tokens Nov 14, 2026

This branch was successfully deployed

1 active deployment
github-app-auth — 3d9bd4a6 Deployed Nov 14, 2026 by Namraa310806 via add_label #27845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants