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

Sanitize inputs #40

Closed
crookse opened this issue May 29, 2020 · 7 comments · Fixed by #108
Closed

Sanitize inputs #40

crookse opened this issue May 29, 2020 · 7 comments · Fixed by #108
Assignees
Labels
Priority: Low Type: Enhancement This item introduces a new feature

Comments

@crookse
Copy link
Member

crookse commented May 29, 2020

Currently, the postgres plugin doesn't sanitize inputs. We should add logic to sanitize our inputs before they're entered into the database. We have some good validation as a starting point in the user_model.ts file. We should expand on our validation efforts.

You can test this by following the steps below:

  1. Log in with user1@hotmail.com / Userpass1
  2. Go to the Settings page.
  3. Update your bio with the following:
' WHERE id = '1'; UPDATE users SET username = 'test

Notice that you're username becomes test.

@crookse crookse added the Type: Enhancement This item introduces a new feature label May 29, 2020
@ebebbington
Copy link
Member

Do you have an idea of how this would be implemented? I'm used to using PDO or having the framework used do this, but not manually

@crookse
Copy link
Member Author

crookse commented May 30, 2020

We could just change special characters to entities before they go into the database and then convert them back when we retrieve them

@ebebbington
Copy link
Member

Course nice, one, i was thinking of the whole query which is where i was going wrong

So i guess the end result would be:

  • All CRUD methods would call a new escapeQueryData method (or whatever name is best) before calling this.prepare
  • SELECT method would call a unescapeDBResult (or whatever name is best) to unescape the data at the end of the method, before returning it

@ebebbington
Copy link
Member

Asked in pgc4d and deno-postgres to see if they currently have sanitisation implemented, or any plans to. Mainly because it would save us a job of doing it manually.

Note that there is another postgres module mentioned but by no means am i suggestion it, just trying to get as much info as possible

@ebebbington
Copy link
Member

Author of pgc4d replied here, and they do encode queries when used with placeholders

@ebebbington
Copy link
Member

Seems like deno-postgres does: await client.query("SELECT * FROM ids WHERE id < $1;", 2). Worth checking as hadn't had any confirmation from the owner

@ebebbington
Copy link
Member

Postgress currently doesn't, but they do parameterise queries so it means we can strip out logic we have added to do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low Type: Enhancement This item introduces a new feature
Development

Successfully merging a pull request may close this issue.

2 participants