-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(signup): throttle user account creation #619
Conversation
f354047
to
243dd46
Compare
15f3808
to
20a6303
Compare
|
||
class ThrottleSignup | ||
{ | ||
public function handle(Request $request, Closure $next, string $limit, string $range) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I'm doing something wrong here, but I couldn't convince Laravel to accept extra arguments of different types: they either have to be all string
or all int
(when ideally this would be int $limit, string $range
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limitation might have something to do with variadic functions.
It is also possible to add a type declaration before the ... token. If this is present, then all arguments captured by ... must match that parameter type.
from https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list
Log::warning("WARN_SIGNUP_THROTTLED: Given limit of '$limit' in range '$range' was exceeded, attempted account creation was blocked."); | ||
return response()->json( | ||
["errors" => "Due to high load, we're currently not able to create an account for you. Please try again tomorrow or reach out through our contact page."], | ||
429 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if a 429 is super correct here, but everything else 4xx fits even worse https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe 503 would be a better choice as it's not really the client's fault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think 503 might be more fitting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'll sneak this in still before merging.
|
||
class ThrottleSignup | ||
{ | ||
public function handle(Request $request, Closure $next, string $limit, string $range) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limitation might have something to do with variadic functions.
It is also possible to add a type declaration before the ... token. If this is present, then all arguments captured by ... must match that parameter type.
from https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list
Log::warning("WARN_SIGNUP_THROTTLED: Given limit of '$limit' in range '$range' was exceeded, attempted account creation was blocked."); | ||
return response()->json( | ||
["errors" => "Due to high load, we're currently not able to create an account for you. Please try again tomorrow or reach out through our contact page."], | ||
429 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think 503 might be more fitting
Ticket https://phabricator.wikimedia.org/T335963
Requires wmde/wbaas-deploy#983 wbstack/charts#121 wbstack/ui#700