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

Cognito - No password validation in admin_set_user_password/sign_up #5259

Closed
JorisLimousin opened this issue Jun 24, 2022 · 13 comments · Fixed by #5768
Closed

Cognito - No password validation in admin_set_user_password/sign_up #5259

JorisLimousin opened this issue Jun 24, 2022 · 13 comments · Fixed by #5768
Assignees

Comments

@JorisLimousin
Copy link

Hi,

There is currently no password validation being performed on the admin_set_user_password function. (and I believe the same is applicable to change_password but I haven't tested it)

As you can see, the password being provided is simply just put into the variable without any checks happening: https://github.com/spulec/moto/blob/d03891e80577be85a49b61cfa686222516d753e9/moto/cognitoidp/models.py#L1786

Same for change_password here: https://github.com/spulec/moto/blob/d03891e80577be85a49b61cfa686222516d753e9/moto/cognitoidp/models.py#L1458

Passwords should be validated against the default Cognito requirements when it comes to minimum password length, (>5 characters) maximum password length (<99 characters), valid characters and against the password policy that has been configured on the user pool. (see https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-policies.html)

If validations fail, it should raise either a ClientError exception with the code InvalidPasswordException, or a ParamValidationError exception. I'm not too sure I remember in which cases one is raised over the other though.

@bblommers
Copy link
Collaborator

Hi @JorisLimousin, will mark it as an enhancement to add validation here.

If this is something you'd like to add yourself, PR's are always welcome!

@RahiBhensdadia
Copy link
Contributor

I find this interesting and I want to work on this. It would be great if I can get the approval from the owner.

@bblommers bblommers changed the title Cognito - No password validation in admin_set_user_password Cognito - No password validation in admin_set_user_password/sign_up Sep 28, 2022
@bblommers
Copy link
Collaborator

Any solution to this should add the same validation to the sign_up-method - see the linked issue where this feature is requested.

@aarushisoni
Copy link
Contributor

hi i want to contribute to this issue

@aarushisoni
Copy link
Contributor

import re
import boto3
from botocore.exceptions import ClientError

class InvalidPasswordException(Exception):
"Raised when the input value is less than 18"
pass

def admin_set_user_password(password):
tmp = password
lgt = len(tmp)
print(tmp)
try:
if(lgt > 5 and lgt <99):
flagl = True
else:
flagl = False
for i in tmp:
if i in "0123456789":
flagn = True
else:
flagn = False
sc = "^ $ * . [ ] { } ( ) ? ! @ # % & / \ , > < ' : ; | _ ~ ` = + -"
for i in tmp:
if i in sc:
flagsc = True
break
else:
flagsc = False

	for i in tmp:
		if(bool(re.match('[A-Z]', i))):
			flagu = True
			break
		else:
			flagu = False
			
	for i in tmp:
		if(bool(re.match('[a-z]', i))):
			flaglo = True
			break
		else:
			flaglo = False
	print(flagl,flagn,flagsc,flagu,flaglo)
	if(flagl and flagn and flagsc and flagu and flaglo):
		print("Password is valid")
	else:
		raise InvalidPasswordException
#except ClientError as e:
#	print("Exception occured",e)
except InvalidPasswordException:
	print("Invalid password")
except ClientError as e:
	print(e)

This is the code I drafted to check the validation of password, Let me know whether it is correct so that I can raise pr for this.

@bblommers
Copy link
Collaborator

Thanks @aarushisoni - the logic looks correct to me. I may have some suggestions to improve things, but I'll add them to the PR itself - that's easier to review.

@aarushisoni
Copy link
Contributor

I worked very hard to solve this issue
Please let me raise the pr and also assign me this issue.

@bblommers
Copy link
Collaborator

You should be able to raise a PR from your own fork. See this GitHub help page on how to do this: https://docs.github.com/en/get-started/quickstart/contributing-to-projects

We have some tips on how to setup Moto: http://docs.getmoto.org/en/latest/docs/contributing/installation.html

And, while I'm sharing links to read: if running make init gives an error, this thread might help: #5547 (comment)

@aarushisoni
Copy link
Contributor

I have raised this Validate Password function is added #5757. Please review it.

@aarushisoni
Copy link
Contributor

i have updated changes in pr kindly review

@aarushisoni
Copy link
Contributor

aarushisoni commented Dec 13, 2022

@bblommers could you please check my latest changes and let me know.

@aarushisoni
Copy link
Contributor

@bblommers hi! Thank you for merging my pr. Can you please tell me by when the issue will be closed

@bblommers
Copy link
Collaborator

Done! Thanks again for contributing to Moto @aarushisoni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants