Loading
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_createApplicationRateLimiterkey: 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.logwith the same shape ascheck_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_limitflag (gitlab_com_derisk, default off) is enabled. The service then returns an error withreason: :rate_limited. The hand-raise controller answers429, 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
- https://gitlab.com/gitlab-org/gitlab/-/work_items/635543
- Rollout issue: #636797
- Same pattern for trials: !265662 (merged)
- Related: !265669 (merged)
How to set up and validate locally
- As a member of a Free group, submit the hand-raise ("Contact sales") form 11 times within an hour.
- The 11th lead is logged in
log/auth_json.logwith"env":"hand_raise_lead_create_request_limit"and is still sent. - Enable the flag in a Rails console with
Feature.enable(:enforce_hand_raise_lead_rate_limit), then submit again. The response is429 Too Many Requestsand 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.