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

Add all info from signup post to get_or_create_user #48

Merged
merged 2 commits into from
Feb 8, 2019

Conversation

leportella
Copy link
Collaborator

When creating a new user with email, the handler was not passing this information to the function get_or_create_user and the email was not being stored. This fixes this problem

password = self.get_body_argument('password', strip=False)
user = self.authenticator.get_or_create_user(username, password)
body = self.request.body.decode('utf-8')
body_arguments = dict(parse.parse_qsl(body))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does self.request.get_arguments() work instead?

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 we should explicitly list the arguments we wanna pass, since POST can contain arbitrary variables. For example, what happens if POST contains an 'id' parameter? Does that allow users to override ID? Or it might cause problems for a new paramter we introduce in the future...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, never trust user input! https://www.enisa.europa.eu/publications/info-notes/the-dangers-of-trusting-user-input (and plenty of other things on the web). Always whitelist and validate that what we are getting is something we explicitly allow

Copy link
Collaborator Author

@leportella leportella Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it will probably override it. I'll have to restructure this to avoid this kind of problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the get_arguments return a dictionary but every result is a list of bytes. Like this:

{'username': [b'john'], 'pw': [b'password']}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, https://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.get_arguments says it should be unicode. I wonder if this is a version thing?

But yeah, whitelisting is more important than the get_arguments

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you think is best. Could you explain please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry. by 'whitelisting', I mean we should only accept and use arguments from the user explicitly, like you were doing before this PR with:

         password = self.get_body_argument('password', strip=False)

Similarly, we should have

         password = self.get_body_argument('password', strip=False)
         email = self.get_body_argument('email', strip=False)

This way, when looking at the code, we know exactly what arguments are being passed through, rather than relying on the right set of arguments to come from the user and be considered 'safe'

try:
user_info = UserInfo(**infos)
self.db.add(user_info)
except AssertionError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What raises an AssertionError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the email is not validated by the ORM function, it will return an AssertionError. We can see this behavior being tested here:

def test_validate_method_wrong_email(email, tmpdir, app):

@yuvipanda yuvipanda merged commit d61d39b into master Feb 8, 2019
@lambdaTotoro lambdaTotoro deleted the add-email-info branch September 29, 2021 17:15
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