Skip to content

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

Description

@hannesvdvreken

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"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions