Skip to content
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

Merged
merged 10 commits into from
Jul 13, 2023
Merged

feat(signup): throttle user account creation #619

merged 10 commits into from
Jul 13, 2023

Conversation

m90
Copy link
Contributor

@m90 m90 commented Jul 10, 2023

@m90 m90 force-pushed the fr/signup-throttle branch 11 times, most recently from f354047 to 243dd46 Compare July 10, 2023 11:46
@m90 m90 force-pushed the fr/signup-throttle branch from 243dd46 to 36e6a29 Compare July 10, 2023 12:27
@m90 m90 force-pushed the fr/signup-throttle branch from 20a6303 to b909eb6 Compare July 10, 2023 13:03
@m90 m90 marked this pull request as ready for review July 10, 2023 13:13

class ThrottleSignup
{
public function handle(Request $request, Closure $next, string $limit, string $range)
Copy link
Contributor Author

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).

Copy link
Contributor

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
Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

config/wbstack.php Outdated Show resolved Hide resolved

class ThrottleSignup
{
public function handle(Request $request, Closure $next, string $limit, string $range)
Copy link
Contributor

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
Copy link
Contributor

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

@m90 m90 merged commit 6d24ab7 into main Jul 13, 2023
@m90 m90 deleted the fr/signup-throttle branch July 13, 2023 11:02
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.

2 participants