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

Adding validations for body of request. #148

Open
Aryaman1706 opened this issue Mar 13, 2021 · 6 comments
Open

Adding validations for body of request. #148

Aryaman1706 opened this issue Mar 13, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@Aryaman1706
Copy link

Feature Request

  • Adding validation for body/query params of express:Request.

Advantages

  • Surety of client-side data we are working with.
  • Prevention from various types of attacks including cross-site scripting, command injection, etc

Implementation

  • I would like to work on this issue. Can you please assign this issue to me?
  • There are a number of npm libraries to implement this Joi, Yup, express-validatior, validatorjs etc.

Additional Context

@anandbaburajan
Copy link
Owner

Hey @Aryaman1706! Thanks for opening this issue! We had thought about validation but didn't think much on the security aspect. Can you check out my comments at #159 too and let us know what you think here? Also, do you find any vulnerabilities in our API already? Thanks again!

@Aryaman1706
Copy link
Author

Hey @anandbaburajan ! I read that discussion and I somewhat agree that mongoose validators could do the job, but don't you think that in case of an invalid request body, we should not allow the data to reach the saving stage as mongoose validators are pre-save hooks? I think we should keep validation of request as a separate step, this way we could save on some unnecessary operations being performed and would be able to deliver intuitive error messages to users. Also if you use something like yup, we could also reuse the validation schema on react side as well with formik for validating it there and then.

I have not tested the API thoroughly, I am gonna do it tonight and would get back if I found some issues.
Meanwhile here are some I found:-

  • Here let's say we pass in a number instead of an array then we would get an error vote.choices.every is not a function. Though this is will fall in catch block but the message is not clear for an average user.
  • Here if we do not provide the field of encryptedEmailID, we would get an error like can not make Buffer from undefined (inside decrypt function) and this statement is not inside trycatch block so this might break the API.

Thanks a lot for addressing the raised issue so soon and I would love to discuss the issue further.

@anandbaburajan
Copy link
Owner

don't you think that in case of an invalid request body, we should not allow the data to reach the saving stage as mongoose validators are pre-save hooks? I think we should keep validation of request as a separate step, this way we could save on some unnecessary operations being performed and would be able to deliver intuitive error messages to users.

I agree, validattion would be good. But since the only user of this API would be the RM-client, do you suggest handling the necessary validation only at the client provided the server handles all the edge cases like the ones you mentioned?

  • Here if we do not provide the field of encryptedEmailID, we would get an error like can not make Buffer from undefined (inside decrypt function) and this statement is not inside trycatch block so this might break the API.

Good catch, thanks! You're welcome to fix it.

Thanks a lot for addressing the raised issue so soon and I would love to discuss the issue further.

Thanks for your thoughts! :D please let me know what you think!

@Aryaman1706
Copy link
Author

I agree, validation would be good. But since the only user of this API would be the RM-client, do you suggest handling the necessary validation only at the client provided the server handles all the edge cases like the ones you mentioned?

  • I agree that since only one consuming the API is RM-client. I am already concerned about miscellaneous users if anyone gets the API endpoints, they could exploit some parts.
  • Also, I am of the opinion that a self-contained API would go a long way as it could be integrated easily with a discord/slack bot or a chrome extension. We could take this project to the moon. by making more utilities for RocketMeet like bots or extensions.

Good catch, thanks! You're welcome to fix it

Sure, I am on it. Would soon raise a PR to fix the same.

Thanks a lot.

@anandbaburajan
Copy link
Owner

a self-contained API would go a long way as it could be integrated easily with a discord/slack bot or a chrome extension

Good point, makes sense, thanks! You're welcome to go ahead with validation. :D

@anandbaburajan anandbaburajan added the enhancement New feature or request label Mar 16, 2021
@anandbaburajan anandbaburajan transferred this issue from another repository Mar 2, 2022
@anandbaburajan
Copy link
Owner

Update: our API endpoints are now inside pages/api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants