Rate limit hand-raise leads per user

What does this MR do and why?

Every hand-raise lead is sent to CustomersDot through GitlabSubscriptions::CreateHandRaiseLeadService: the hand-raise form, the subscription welcome step and the cart-abandonment workers. Nothing limits how many leads one user sends.

  • Adds a hand_raise_lead_create ApplicationRateLimiter key: 10 leads per hour per user, checked in the service before the CustomersDot call.
  • The service now takes the user (new(user:)). The REST client only sees a params hash, and the cart-abandonment params carry no user ID.
  • Leads over the limit are logged to auth.log with the same shape as check_rate_limit! (Application_Rate_Limiter_Request, env: hand_raise_lead_create_request_limit, user_id, username). The service runs in workers too, so there is no request to log from.
  • Leads over the limit are skipped only when the enforce_hand_raise_lead_rate_limit flag (gitlab_com_derisk, default off) is enabled. The service then returns an error with reason: :rate_limited. The hand-raise controller answers 429, the workers already ignore the result, and the welcome step already logs a failed lead and continues.

The limit will be added to the GitLab.com rate limits docs once it is enforced.

References

How to set up and validate locally

  1. As a member of a Free group, submit the hand-raise ("Contact sales") form 11 times within an hour.
  2. The 11th lead is logged in log/auth_json.log with "env":"hand_raise_lead_create_request_limit" and is still sent.
  3. Enable the flag in a Rails console with Feature.enable(:enforce_hand_raise_lead_rate_limit), then submit again. The response is 429 Too Many Requests and no lead is sent.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

🤖 Generated with Claude Code

Merge request reports

Loading
Loading