Skip to content

🔒 Fix Tenant Isolation Failure in Webhooks and Interactions#6

Open
CaioIsCoding wants to merge 1 commit intomainfrom
fix-tenant-isolation-vulnerability-8567954283396659769
Open

🔒 Fix Tenant Isolation Failure in Webhooks and Interactions#6
CaioIsCoding wants to merge 1 commit intomainfrom
fix-tenant-isolation-vulnerability-8567954283396659769

Conversation

@CaioIsCoding
Copy link
Owner

The fix addresses a critical tenant isolation failure where webhooks and user interactions were being associated with the first tenant in the database regardless of the actual sender or instance.

Key changes:

  1. In app/api/v1/webhooks.py, the evolution_webhook now:
    • Identifies the tenant by joining with SocialAccount and filtering by the instance name from the payload.
    • Falls back to looking up the tenant by checking if the sender's remote_jid is in the admin_jids list.
    • Correctly associates newly created tenants with the sender and instance.
  2. In app/services/interaction.py, handle_message now:
    • Joins ContentJob with Tenant and filters by Tenant.admin_jids.contains([remote_jid]).
    • This ensures that admins can only interact with jobs belonging to their own tenants.

These changes prevent unauthorized users from viewing or approving content from other tenants.


PR created automatically by Jules for task 8567954283396659769 started by @CaioIsCoding

…teraction service

- Replaced unfiltered `db.query(Tenant).first()` with secure lookups based on Evolution API instance name and sender's WhatsApp JID.
- Modified `InteractionService.handle_message` to filter content jobs by the sender's authorized tenant.
- Ensured new tenants created via webhooks are correctly associated with their Evolution API instances and admins.
- Prevents cross-tenant data access and unauthorized command execution.

Co-authored-by: CaioIsCoding <106751132+CaioIsCoding@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant