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

Idea: add fool protection in "start" function to avoid accidental ban for flood #664

Open
Lopol2010 opened this issue Apr 16, 2024 · 0 comments

Comments

@Lopol2010
Copy link

Steps to reproduce:

  1. By accident I made phoneCode callback to always return the same resolved promise.
  2. And did not return true from onError callback.
  3. Then I invalidated code by sending it to my bot's private chat, so that auth.SignIn throws PhoneCodeExpiredError.

In a couple of seconds this combination got my account banned for flood for 1 hour, due to hundreds of signIn attempts before I stopped the server manually.

Relevant while loop:

while (1) {
try {
try {
phoneCode = await authParams.phoneCode(isCodeViaApp);
} catch (err: any) {
// This is the support for changing phone number from the phone code screen.
if (err.errorMessage === "RESTART_AUTH") {
return client.signInUser(apiCredentials, authParams);
}
}
if (!phoneCode) {
throw new Error("Code is empty");
}
// May raise PhoneCodeEmptyError, PhoneCodeExpiredError,
// PhoneCodeHashEmptyError or PhoneCodeInvalidError.
const result = await client.invoke(
new Api.auth.SignIn({
phoneNumber,
phoneCodeHash,
phoneCode,
})
);
if (result instanceof Api.auth.AuthorizationSignUpRequired) {
isRegistrationRequired = true;
termsOfService = result.termsOfService;
break;
}
return result.user;
} catch (err: any) {
if (err.errorMessage === "SESSION_PASSWORD_NEEDED") {
return client.signInWithPassword(apiCredentials, authParams);
} else {
const shouldWeStop = await authParams.onError(err);
if (shouldWeStop) {
throw new Error("AUTH_USER_CANCEL");
}
}
}
}

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

No branches or pull requests

1 participant