Skip to content

fix(webhooks): stop returning 500 for Free, Pro and unknown subscription names - #207

Open
gerardosabetta wants to merge 1 commit into
hackthebox:mainfrom
gerardosabetta:fix/subscription-change-unknown-plan
Open

gerardosabetta wants to merge 1 commit into
hackthebox:mainfrom
gerardosabetta:fix/subscription-change-unknown-plan

Conversation

@gerardosabetta

@gerardosabetta gerardosabetta commented Nov 10, 2026 •

Copy link
Copy Markdown

Types of changes

  • Bugfix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality not to work as expected).
  • Documentation Update (if none of the other choices applies).

Proposed changes

Refs #205. POST /webhook with a SubscriptionChange event returned HTTP 500 when properties.subscription_name was Free or Pro, because the handler raised ValueError for any name without a role.

subscription_name Before After
vip, dedivip 200, role granted unchanged
Free (any case) 500 200, the member's subscription_labs role is removed if they hold one
Pro 500 422 and a warning log, until a role with key Pro is configured
any other unknown name 500 422 and a warning log, no Discord call
  • The lookup now searches only the subscription_labs category. get_post_or_rank also searched position, rank and creator roles, so a name such as Hacker resolved to a rank role and then failed the group check.
  • An unknown name is rejected before the member is fetched from Discord.
  • httpx is added to the dev dependency group. The new end-to-end tests use it to call the FastAPI app.

Decisions for the reviewer

The issue says the fix needs two product decisions. This PR takes a position on one and leaves the other open:

  1. Free removes the subscription role. The alternative is to acknowledge the event and change nothing. That is a one-line change in _NO_ROLE_SUBSCRIPTIONS handling.
  2. Pro is not mapped in code. After this PR, Pro events get a 422 instead of a 500. They start to succeed when an admin adds a subscription_labs dynamic role with key Pro. If Pro must map to the existing vip or dedivip role, say which one and I will add it. This is why the PR says "Refs" and not "Fixes".

Checklist

  • I have read and followed the CONTRIBUTING.md doc.
  • Lint and unit tests pass locally with my changes.
  • I have added the necessary documentation (if appropriate).

CONTRIBUTING.md asks for an assignee on the issue before a PR is opened. I am not assigned to #205, so I left that box open; close this PR if someone else owns the fix.

Unit tests pass locally: 366 passed on Python 3.13. flake8 reports 12 findings in src/webhooks/handlers/mp.py on main and the same 12 with this change, so I left the lint box open. The new test file has no findings.

Additional context

The first commit of this work was a reproduction: a signed request through the real app, MPHandler and RoleManager (env fallback roles), with only Discord mocked. Free and Pro returned 500 with the traceback from the issue. That file is now tests/src/webhooks/test_subscription_change_webhook.py and asserts the new behaviour. Not verified against the production database or a real guild.

🤖 Generated with Claude Code

…ion names

SubscriptionChange now removes the subscription role for Free, returns 422
with a warning for a name that has no subscription_labs role, and no longer
resolves names against rank or position roles.

Refs hackthebox#205

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@gerardosabetta

Copy link
Copy Markdown
Author

A six-slide walkthrough of this change: the bug, the before and after per plan name, the verification, and the two decisions left for the reviewer.

Slide 1: Subscription webhooks stop returning 500 for Free and Pro

Slide 2: Every Free or Pro event failed with a 500

Slide 3: What POST /webhook answers for each plan name

Slide 4: Three changes inside one handler

Slide 5: What was run, and where

Slide 6: Two decisions for the reviewer

This branch has not been deployed

No deployments
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