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

PUT / DELETE requests don't do crumb validation #161

Open
hannesvdvreken opened this issue Aug 9, 2022 · 0 comments
Open

PUT / DELETE requests don't do crumb validation #161

hannesvdvreken opened this issue Aug 9, 2022 · 0 comments
Labels
support Questions, discussions, and general support

Comments

@hannesvdvreken
Copy link

hannesvdvreken commented Aug 9, 2022

It's very common in other frameworks to do REST routes as such:

(request: Request, h: ResponseToolkit): symbol => {
  if (request.method === 'post' && request.url.searchParams.has('_method')) {
    const override = request.url.searchParams.get('_method');
    request.setMethod(override);
  }

  return h.continue;
};

These are some example routes:

{
  path: '/articles',
  method: 'POST',
  options: {
    validate: {
      payload: Joi.object({
        name: Joi.string(),
      });
    },
  },
  handler: store,
},
{
  path: '/articles/{slug}',
  method: 'PUT',
  options: {
    validate: {
      payload: Joi.object({
        name: Joi.string(),
      });
    },
  },
  handler: save,
},

POST will succeed, PUT will fail because

errors: {
  "crumb": "\"crumb\" is not allowed"
}
@hannesvdvreken hannesvdvreken added the support Questions, discussions, and general support label Aug 9, 2022
@hannesvdvreken hannesvdvreken changed the title POST / DELETE requests don' POST / DELETE requests don't do crumb validation Aug 9, 2022
@hannesvdvreken hannesvdvreken changed the title POST / DELETE requests don't do crumb validation PUT / DELETE requests don't do crumb validation Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

1 participant