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

Polluted request.payload by adding undefined field #187

Closed
kierandg opened this issue Mar 1, 2014 · 2 comments
Closed

Polluted request.payload by adding undefined field #187

kierandg opened this issue Mar 1, 2014 · 2 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@kierandg
Copy link

kierandg commented Mar 1, 2014

When upgrade to Hapi 2.x, Joi validation polluted request.payload and OAuth signature checking in my app failed. It didn't happen in hapi 1.x with Joi 2. I think that validating the request should not pollute request.payload.

var hapi = require('hapi');

exports.demo = {
    handler: function(request) {
        console.log(request.payload)
        // Output { param1: undefined }
    },
    validate: {
        payload: hapi.types.object({
            param1: hapi.types.string().optional()
        }).options({
            allowUnknown: true
        })
    }
};
@hueniverse
Copy link
Contributor

What was the actual payload sent?

@ryanfitz
Copy link

I'm currently in the process of upgrading an api server from Hapi 2.1.2 to 2.6.0 and I'm also seeing all optional params in the payload are being set to undefined. I haven't tried any version between 2.1 & 2.6, but with 2.1 optional params are not set.

Example json I'm posting:

{
  "input": "http://cdn.needsupply.com/media/catalog/product/cache/1/image/460x590/e9607dc71bc010050ca2ae6f644b84c1/1/0/1003913_front.jpg",
  "outputKeyPrefix" : "SOMEIDENTIFIER",
  "outputs": [
    { "key": "original", "formats" : ["jpg", "webp"] },
    { "key": "large", "height": 400, "width": 320, "formats" : ["jpg", "webp"] },
    { "key": "small", "height": 200, "width": 160, "formats" : ["jpg", "webp"] }
  ]
}

Schema:

internals.outputSchema = Obj({
  key: S().required().notes('name of the transcoded file'),
  height: N().min(1).optional().notes('max resize height'),
  width: N().min(1).optional().notes('max resize width'),
  quality: N().min(1).max(100).optional().notes('image quality setting'),
  formats: array().includes(S().valid('jpg', 'webp', 'png')).required()
});

internals.transcodeSchema = {
  input : S().regex(internals.urlPattern).required(),
  outputKeyPrefix : S().required(),
  outputs: array().includes(internals.outputSchema).required(),
  notifyUrl : S().optional()
};

Every optional parameter both on the top level object as well as the nested array of outputSchema's are set to undefined

@hueniverse hueniverse added the bug label Mar 11, 2014
@hueniverse hueniverse added this to the 2.8.0 milestone Mar 11, 2014
@hueniverse hueniverse self-assigned this Mar 11, 2014
@hueniverse hueniverse removed this from the 2.8.0 milestone Mar 12, 2014
@hueniverse hueniverse added this to the 2.8.0 milestone Mar 12, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants