Skip to content

Unable to cause an error during payload parsing #4172

@matthieusieben

Description

@matthieusieben

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: v14.14.0
  • module version with issue: 19.2.0
  • last module version without issue: 19.2.0
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information: n.a.

What are you trying to achieve or the steps to reproduce?

I try to implement a plugin that validates that the Digest header matches the payload.

I want to output a nice error message if the payload does not match the header

server.ext('onRequest', (request, h) => {

    const { algorithm, digest } = getDigest(request.headers)

    const hash = Crypto.createHash(algorithm);
    request.events.on('peek', (chunk) => {

        hash.update(chunk);
    });

    request.events.once('finish', () => {

        if (digest !== hash.digest('base64')) throw new Boom.badData('nice error message')
    });

    return h.continue;
});

What was the result you got?

The server crashes due to an uncaught exception.

What result did you expect?

An http error response should be returned.

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