Skip to content

fix: add proper error handling for missing authorization header (#11096)#12597

Open
zendy199x wants to merge 1 commit intoSignificant-Gravitas:devfrom
zendy199x:fix/11096-add-proper-error-handling-for-missing-authorizatio
Open

fix: add proper error handling for missing authorization header (#11096)#12597
zendy199x wants to merge 1 commit intoSignificant-Gravitas:devfrom
zendy199x:fix/11096-add-proper-error-handling-for-missing-authorizatio

Conversation

@zendy199x
Copy link
Copy Markdown

Fixes #11096

Why / What / How

The current authentication dependencies likely raise an ApiError when the Authorization header is missing, but the error message may not be clear or the header extraction logic may not be robust. This change improves header extraction and provides clearer, more actionable error messages.

This PR refactors the authorization header extraction logic in dependencies.py to add proper error handling for missing or malformed Authorization headers, ensuring consistent and informative error responses.

The change introduces explicit checks for the presence and format of the Authorization header before attempting to parse it. If the header is missing, a descriptive error is raised with a clear message indicating the expected format. The implementation avoids relying on implicit behavior or generic exceptions.

Changes 🏗️

  • Updated autogpt_platform/autogpt_libs/autogpt_libs/auth/dependencies.py to:
    • Explicitly check for the presence of the Authorization header
    • Provide a clear error message when the header is missing
    • Improve robustness of header parsing logic

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • ...

For configuration changes:

  • .env.default is updated or already compatible with my changes
  • docker-compose.yml is updated or already compatible with my changes
  • I have included a list of my configuration changes in the PR description (under Changes)

@zendy199x zendy199x requested a review from a team as a code owner March 29, 2026 15:17
Copilot AI review requested due to automatic review settings March 29, 2026 15:17
@zendy199x zendy199x requested review from Bentlybro and kcze and removed request for a team March 29, 2026 15:17
@github-project-automation github-project-automation bot moved this to 🆕 Needs initial review in AutoGPT development kanban Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR targets the master branch but does not come from dev or a hotfix/* branch.

Automatically setting the base branch to dev.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 29, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot changed the base branch from master to dev March 29, 2026 15:17
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f75b8491-a0e1-44a3-9816-e19a2073b196

📥 Commits

Reviewing files that changed from the base of the PR and between 46932df and df397c3.

📒 Files selected for processing (2)
  • autogpt_platform/autogpt_libs/autogpt_libs/auth/dependencies.py
  • autogpt_platform/frontend/Dockerfile
✅ Files skipped from review due to trivial changes (1)
  • autogpt_platform/frontend/Dockerfile
🚧 Files skipped from review as they are similar to previous changes (1)
  • autogpt_platform/autogpt_libs/autogpt_libs/auth/dependencies.py
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: check API types
  • GitHub Check: end-to-end tests
  • GitHub Check: Seer Code Review
  • GitHub Check: test (3.13)
  • GitHub Check: test (3.12)
  • GitHub Check: type-check (3.12)
  • GitHub Check: test (3.11)
  • GitHub Check: Analyze (python)
  • GitHub Check: Check PR Status

Walkthrough

Auth dependency now treats requests as anonymous when credential details are missing and disables admin impersonation if the X-Act-As-User-Id header, after trimming, equals "none" (case-insensitive). Frontend production Docker base image updated to node:22.22-alpine3.23.

Changes

Cohort / File(s) Summary
Authentication Handling
autogpt_platform/autogpt_libs/autogpt_libs/auth/dependencies.py
Return None when credentials or credentials.credentials is absent (log debug); treat trimmed X-Act-As-User-Id == "none" (case-insensitive) as disabling admin impersonation.
Frontend Dockerfile
autogpt_platform/frontend/Dockerfile
Production stage base image changed from node:21-alpine to node:22.22-alpine3.23; no other production-stage instructions altered.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Possible security concern, Review effort 3/5

Poem

🐰 I sniff the headers, trim the fluff,

"none" hops past — I call that enough.
When creds are hiding, I tiptoe by,
Quiet paws beneath a debug sky,
A tiny rabbit guards the auth stuff!

🚥 Pre-merge checks | ✅ 1 | ❌ 4

❌ Failed checks (3 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title describes a code change (adding error handling for missing authorization header) but the actual changes include modifying JWT parsing behavior and updating a Docker base image, which aren't mentioned in the title. Update the title to reflect the actual changes made, such as 'fix: improve authorization header handling and update Node.js version' or split into focused PRs.
Description check ⚠️ Warning The description claims to refactor authorization header extraction with explicit checks and error messages, but the actual changes show modifications to JWT parsing logic and Docker base image updates that aren't described. Update the description to accurately reflect changes to both authentication logic and Docker configuration, or separate these changes into distinct pull requests.
Out of Scope Changes check ⚠️ Warning The Dockerfile change updating Node.js from version 21 to 22.22 is unrelated to the stated objective of fixing authorization header error handling. Remove the Dockerfile change or create a separate PR for the Node.js version update, as it is outside the scope of fixing authorization header handling.
Linked Issues check ❓ Inconclusive Issue #11096 requires handling missing authorization headers, but the PR changes show modifications to JWT credentials handling and Docker image version without explicit error handling for missing headers. Clarify whether the PR fully addresses issue #11096's requirements and verify that the authorization header handling matches the issue's specifications.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refines authentication-related dependency behavior in the platform auth library and (separately) updates the frontend Docker image base.

Changes:

  • Adjust get_optional_user_id to treat missing/empty bearer credentials as anonymous access.
  • Treat X-Act-As-User-Id: none (case-insensitive) as “no impersonation”.
  • Update autogpt_platform/frontend Dockerfile base/prod images to Node 22.22 on Alpine 3.23.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
autogpt_platform/frontend/Dockerfile Updates Node/Alpine base images used to build and run the frontend container.
autogpt_platform/autogpt_libs/autogpt_libs/auth/dependencies.py Tightens optional auth credential handling and adds an impersonation-header sentinel behavior.

@zendy199x zendy199x force-pushed the fix/11096-add-proper-error-handling-for-missing-authorizatio branch from 229774a to df4dc9f Compare March 29, 2026 15:33
@github-actions github-actions bot added the platform/frontend AutoGPT Platform - Front end label Mar 29, 2026
@zendy199x zendy199x force-pushed the fix/11096-add-proper-error-handling-for-missing-authorizatio branch from df4dc9f to 46932df Compare March 29, 2026 15:37
…ificant-Gravitas#12561)

## Summary
Upgrade the frontend **Docker image** from **Node.js v21** (EOL since
June 2024) to **Node.js v22 LTS** (supported through April 2027).

> **Scope:** This only affects the **Dockerfile** used for local
development (`docker compose`) and CI. It does **not** affect Vercel
(which manages its own Node.js runtime) or Kubernetes (the frontend Helm
chart was removed in Dec 2025 — the frontend is deployed exclusively via
Vercel).

## Why
- Node v21.7.3 has a **known TransformStream race condition bug**
causing `TypeError: controller[kState].transformAlgorithm is not a
function` — this is
[BUILDER-3KF](https://significant-gravitas.sentry.io/issues/BUILDER-3KF)
with **567,000+ Sentry events**
- The error is entirely in Node.js internals
(`node:internal/webstreams/transformstream`), zero first-party code
- Node 21 is **not an LTS release** and has been EOL since June 2024
- `package.json` already declares `"engines": { "node": "22.x" }` — the
Dockerfile was inconsistent
- Node 22.x LTS (v22.22.1) fixes the TransformStream bug
- Next.js 15.4.x requires Node 18.18+, so Node 22 is fully compatible

## Changes
- `autogpt_platform/frontend/Dockerfile`: `node:21-alpine` →
`node:22.22-alpine3.23` (both `base` and `prod` stages)

## Test plan
- [ ] Verify frontend Docker image builds successfully via `docker
compose`
- [ ] Verify frontend starts and serves pages correctly in local Docker
environment
- [ ] Monitor Sentry for BUILDER-3KF — should drop to zero for
Docker-based runs

Signed-off-by: Zendy <50132805+zendy199x@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/frontend AutoGPT Platform - Front end size/s

Projects

Status: 🆕 Needs initial review
Status: No status

Development

Successfully merging this pull request may close these issues.

ApiError: Authorization header is missing

3 participants