Skip to content

fix(processor): EVO-1546 — WebSocket chat auth crash#111

Merged
DavidsonGomes merged 1 commit into
developfrom
fix/EVO-1546-websocket-auth-crash
May 29, 2026
Merged

fix(processor): EVO-1546 — WebSocket chat auth crash#111
DavidsonGomes merged 1 commit into
developfrom
fix/EVO-1546-websocket-auth-crash

Conversation

@pastoriniMatheus
Copy link
Copy Markdown

@pastoriniMatheus pastoriniMatheus commented May 28, 2026

Summary

  • Fix WebSocket chat 403 — EvoAuthMiddleware bloqueava WS upgrade requests
  • Fix .data AttributeError no get_jwt_token_ws()EvoAuthResponse nao tem .data

Root Cause

Bug 1 (middleware 403): _should_skip() em evo_auth.py nao incluia paths WebSocket. O browser nao envia Authorization header no WS handshake, entao a middleware retornava 403. O WS handler ja faz auth interna via mensagem JSON.

Bug 2 (.data crash): chat_routes.py linha 88 acessava (await auth_service.validate_token(token, "bearer")).data mas validate_token() retorna EvoAuthResponse diretamente (com .user), nao tem .data. Causava AttributeError apos token ser validado com sucesso.

Changes

Arquivo Mudanca
evo-ai-processor-community/src/middleware/evo_auth.py Adicionado /api/v1/chat/ws/ e /api/v1/chat/ws-live/ em skip_prefixes
evo-ai-processor-community/src/api/chat_routes.py Removido .data em validate_token() call

Total: 2 linhas alteradas em 2 arquivos

Impact

  • Zero impacto em rotas HTTP existentes — middleware continua protegendo todas
  • Fix beneficia todos os WS clients (chatbots, A2A, integracoes)
  • Nenhum componente frontend alterado neste PR

Test plan

  • WS conecta sem 403
  • Token validado com sucesso dentro do WS handler
  • IA responde via WebSocket streaming
  • Rotas HTTP continuam protegidas pela middleware

Summary by Sourcery

Fix WebSocket chat authentication failures and runtime crash when validating tokens in the WebSocket handler.

Bug Fixes:

  • Exclude WebSocket chat endpoints from EvoAuth middleware checks to prevent 403 responses during WS upgrade.
  • Correct token validation in the WebSocket chat route to use the EvoAuthResponse object directly instead of accessing a non-existent .data attribute.

…auth fix

Updates processor submodule to include:
- fix(websocket): skip WS routes in EvoAuthMiddleware (403 block)
- fix(websocket): remove .data on EvoAuthResponse in get_jwt_token_ws
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts EvoAuth middleware to bypass authentication for WebSocket chat endpoints and fixes a token validation call in the WebSocket chat route that incorrectly accessed a non‑existent .data attribute on EvoAuthResponse.

File-Level Changes

Change Details Files
Adjust EvoAuth middleware skip logic so WebSocket chat upgrade requests are not blocked with 403.
  • Extend the list of URL prefixes that bypass EvoAuth to include the WebSocket chat endpoints used for WS upgrades
  • Rely on existing in‑handler JSON‑message authentication for these WebSocket routes instead of middleware token validation during the handshake
evo-ai-processor-community/src/middleware/evo_auth.py
Fix WebSocket chat handler to use EvoAuthResponse correctly when validating tokens.
  • Change the token validation call to use the EvoAuthResponse object directly instead of reading a non‑existent .data attribute
  • Ensure successful token validation no longer raises AttributeError inside the WebSocket chat handler
evo-ai-processor-community/src/api/chat_routes.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Instead of hardcoding /api/v1/chat/ws/ and /api/v1/chat/ws-live/ in skip_prefixes, consider centralizing WebSocket-auth-exempt paths (e.g., a shared constant or config) so future WS endpoints don’t require touching the middleware logic.
  • Add a short code comment in evo_auth.py explaining why WebSocket upgrade paths are skipped (handshake has no Authorization header and auth is done in the WS handler) to make this exception explicit for future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of hardcoding `/api/v1/chat/ws/` and `/api/v1/chat/ws-live/` in `skip_prefixes`, consider centralizing WebSocket-auth-exempt paths (e.g., a shared constant or config) so future WS endpoints don’t require touching the middleware logic.
- Add a short code comment in `evo_auth.py` explaining why WebSocket upgrade paths are skipped (handshake has no Authorization header and auth is done in the WS handler) to make this exception explicit for future maintainers.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@DavidsonGomes DavidsonGomes merged commit 8d31ecb into develop May 29, 2026
3 checks passed
@DavidsonGomes DavidsonGomes deleted the fix/EVO-1546-websocket-auth-crash branch May 29, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants