How to use @hapi/bourne - 7 common examples

To help you get started, we’ve selected a few @hapi/bourne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hapijs / statehood / lib / index.js View on Github external
return {};
    }

    Hoek.assert(typeof value === 'string', 'Invalid string');

    // Encodings: 'base64json', 'base64', 'form', 'iron', 'none'

    if (definition.encoding === 'iron') {
        return await Iron.unseal(value, definition.password, definition.iron || Iron.defaults);
    }

    if (definition.encoding === 'base64json') {
        const decoded = Buffer.from(value, 'base64').toString('binary');
        try {
            return Bourne.parse(decoded);
        }
        catch (err) {
            throw Boom.badRequest('Invalid JSON payload');
        }
    }

    if (definition.encoding === 'base64') {
        return Buffer.from(value, 'base64').toString('binary');
    }

    // encoding: 'form'

    return Querystring.parse(value);
};
github hapijs / iron / lib / index.js View on Github external
const decryptOptions = Hoek.clone(options.encryption);
    decryptOptions.salt = encryptionSalt;

    try {
        decryptOptions.iv = B64.base64urlDecode(encryptionIv, 'buffer');
    }
    catch (err) {
        throw Boom.boomify(err);
    }

    const decrypted = await exports.decrypt(password.encryption, decryptOptions, encrypted);

    // Parse JSON

    try {
        return Bourne.parse(decrypted);
    }
    catch (err) {
        throw new Boom.Boom('Failed parsing sealed object JSON: ' + err.message);
    }
};
github hapijs / joi / test / extend.js View on Github external
method(value, helpers) {

                    if (typeof value !== 'string' ||
                        value[0] !== '[' && !/^\s*\[/.test(value)) {

                        return;
                    }

                    try {
                        return { value: Bourne.parse(value) };
                    }
                    catch (ignoreErr) { }
                }
            }
github stelace / stelace / src / util / validation.js View on Github external
method (value, helpers) {
        if (typeof value !== 'string') return
        if (value[0] !== '{' && !/^\s*\{/.test(value)) return

        try {
          return { value: Bourne.parse(value) }
        } catch (ignoreErr) { }
      }
    }
github hapijs / wreck / lib / index.js View on Github external
internals.tryParseBuffer = function (buffer, next) {

    if (buffer.length === 0) {
        return next(null, null);
    }

    let payload;
    try {
        payload = Bourne.parse(buffer.toString());
    }
    catch (err) {
        return next(Boom.badGateway(err.message, { payload: buffer }));
    }

    return next(null, payload);
};
github outmoded / hapijs.com / lib / redis.js View on Github external
async [getValue](key) {

        const serializedValue = await this[getAsync](key);
        const value = Bourne.parse(serializedValue, null, 'remove');
        return value;
    }
github Asymmetrik / node-fhir-server-core / src / server / utils / prototype-injection-handler.utils.js View on Github external
module.exports = prototypeInjectionHandler = (req, res, next) => {
	try {
		if (req.body && typeof req.body === 'object') {
			Bourne.scan(req.body);
		}
		next();
	} catch (error) {
		let OperationOutcome = require(resolveSchema('3_0_1', 'operationoutcome'));
		let err = new OperationOutcome({
			statusCode: 400,
			issue: [
				{
					severity: 'error',
					code: 'invalid',
					details: {
						text: error.message,
					},
				},
			],
		});

@hapi/bourne

JSON parse with prototype poisoning protection

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

77 / 100
Full package analysis

Popular @hapi/bourne functions