Skip to content

Commit d28ebfb

Browse files
feat: Respect disablePrototypePoisoningProtection option (#99)
Co-authored-by: Josh Mock <[email protected]>
1 parent 490538c commit d28ebfb

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/client.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,21 @@ export default class Client extends API {
215215
this.diagnostic = opts[kChild].diagnostic
216216
} else {
217217
this.diagnostic = new Diagnostic()
218-
this.serializer = new options.Serializer()
218+
219+
let serializerOptions
220+
if (opts.disablePrototypePoisoningProtection != null) {
221+
if (typeof opts.disablePrototypePoisoningProtection === 'boolean') {
222+
serializerOptions = {
223+
enablePrototypePoisoningProtection: !opts.disablePrototypePoisoningProtection
224+
}
225+
} else {
226+
serializerOptions = {
227+
enablePrototypePoisoningProtection: opts.disablePrototypePoisoningProtection
228+
}
229+
}
230+
}
231+
this.serializer = new options.Serializer(serializerOptions)
232+
219233
this.connectionPool = new options.ConnectionPool({
220234
pingTimeout: options.pingTimeout,
221235
resurrectStrategy: options.resurrectStrategy,

test/unit/client.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,49 @@ test('Ensure new client does not time out at default (30s) when client sets requ
504504
t.end()
505505
}
506506
})
507+
508+
test('Pass disablePrototypePoisoningProtection option to serializer', async t => {
509+
let client = new Client({
510+
node: 'http://localhost:9200',
511+
disablePrototypePoisoningProtection: false
512+
})
513+
t.same(client.serializer[symbols.kJsonOptions], {
514+
protoAction: 'error',
515+
constructorAction: 'error'
516+
})
517+
518+
client = new Client({
519+
node: 'http://localhost:9200',
520+
disablePrototypePoisoningProtection: true
521+
})
522+
t.same(client.serializer[symbols.kJsonOptions], {
523+
protoAction: 'ignore',
524+
constructorAction: 'ignore'
525+
})
526+
527+
client = new Client({
528+
node: 'http://localhost:9200',
529+
disablePrototypePoisoningProtection: 'proto'
530+
})
531+
t.same(client.serializer[symbols.kJsonOptions], {
532+
protoAction: 'error',
533+
constructorAction: 'ignore'
534+
})
535+
536+
client = new Client({
537+
node: 'http://localhost:9200',
538+
disablePrototypePoisoningProtection: 'constructor'
539+
})
540+
t.same(client.serializer[symbols.kJsonOptions], {
541+
protoAction: 'ignore',
542+
constructorAction: 'error'
543+
})
544+
})
545+
546+
test('disablePrototypePoisoningProtection is true by default', async t => {
547+
const client = new Client({ node: 'http://localhost:9200' })
548+
t.same(client.serializer[symbols.kJsonOptions], {
549+
protoAction: 'ignore',
550+
constructorAction: 'ignore'
551+
})
552+
})

0 commit comments

Comments
 (0)