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

Added middleware for subscribe API #1102

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

arpit01923
Copy link

@arpit01923 arpit01923 commented May 20, 2023

Added middleware for /challenge/subscribe API. So that -

  • This can prevent security issues.
  • It avoids users to send any data to this endpoint.
  • This can prevent to potential vulnerabilities and exploits.

Issue - #1017

@khushi818 khushi818 self-requested a review May 22, 2023 14:47
khushi818
khushi818 previously approved these changes May 22, 2023
Copy link
Contributor

@khushi818 khushi818 left a comment

Choose a reason for hiding this comment

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

LGTM

@shubhamsinghbundela
Copy link
Contributor

Nit:- can you please connect issue ticket in description

shubhamsinghbundela

This comment was marked as off-topic.

@@ -17,6 +17,22 @@ const createChallenge = async (req, res, next) => {
}
};

const subscribeToChallenge = async (req, res, next) => {
const schema = joi.object().strict().keys({
userId: joi.string().guid({ version: 'uuidv4' }).required(),
Copy link
Contributor

@shubhamsinghbundela shubhamsinghbundela May 24, 2023

Choose a reason for hiding this comment

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

Can you please explain why you used version: 'uuidv4' ?
because I am not seeing it is used anywhere in backend repo validator file
cc: @heyrandhir @RitikJaiswal75

Copy link
Contributor

Choose a reason for hiding this comment

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

We actually dont need this here. @arpit01923 Could you point me to the file where we are using uuid in userid?

Copy link
Contributor

@RitikJaiswal75 RitikJaiswal75 left a comment

Choose a reason for hiding this comment

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

Please write tests where you return bad request error for something that does not follow the schema

@@ -17,6 +17,22 @@ const createChallenge = async (req, res, next) => {
}
};

const subscribeToChallenge = async (req, res, next) => {
const schema = joi.object().strict().keys({
userId: joi.string().guid({ version: 'uuidv4' }).required(),
Copy link
Contributor

Choose a reason for hiding this comment

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

We actually dont need this here. @arpit01923 Could you point me to the file where we are using uuid in userid?

const subscribeToChallenge = async (req, res, next) => {
const schema = joi.object().strict().keys({
userId: joi.string().guid({ version: 'uuidv4' }).required(),
challengeId: joi.string().guid({ version: 'uuidv4' }).required(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just keep the id as string? to compare that id is unique we need some some other userIds, but since here a single user id is being passed we are ok considering the user id as string.

Copy link
Author

Choose a reason for hiding this comment

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

Ok got it @RitikJaiswal75, removed uuid from validator

Copy link
Contributor

@RitikJaiswal75 RitikJaiswal75 left a comment

Choose a reason for hiding this comment

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

Please write the tests for the validator written


router.get("/", authenticate, challenges.fetchChallenges);
router.post("/", authenticate, createChallenge, challenges.createChallenge);
router.post("/subscribe", authenticate, challenges.subscribeToChallenge);
router.post("/subscribe", authenticate, subscribeToChallenge, challenges.subscribeToChallenge);

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
This route handler performs
authorization
, but is not rate-limited.
Copy link
Member

@iamitprakash iamitprakash left a comment

Choose a reason for hiding this comment

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

please add test case coverage stats

Copy link
Contributor

@RitikJaiswal75 RitikJaiswal75 left a comment

Choose a reason for hiding this comment

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

Please add a picture of coverage that shows, how many lines of code were covered and branches are covered.

next();
} catch (error) {
logger.error(`Error validating subscribeToChallenge payload : ${error}`);
res.boom.badRequest(error.details[0].message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @arpit01923, sending the exact error message to the end user might be harmful and can expose critical information on the backend Making us prone to external threats.

We already have a response saved in constants file which can be used here to send back to the end user.

Copy link
Author

@arpit01923 arpit01923 Jun 19, 2023

Choose a reason for hiding this comment

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

error message changed

Copy link
Contributor

Choose a reason for hiding this comment

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

Please write a test for the middleware in tests/unit/middleware.

Copy link
Author

Choose a reason for hiding this comment

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

Already written
image

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.

None yet

5 participants