@@ -724,29 +724,55 @@ describe('bodyParser.json()', function () {
724
724
725
725
describe ( 'prototype poisoning' , function ( ) {
726
726
it ( 'should parse __proto__ when protoAction is set to ignore' , function ( done ) {
727
- request ( createServer ( { onProtoPoisoning : 'ignore' } ) )
727
+ request ( createServer ( { onProto : { onProtoPoisoning : 'ignore' } } ) )
728
728
. post ( '/' )
729
729
. set ( 'Content-Type' , 'application/json' )
730
730
. send ( '{"user":"tobi","__proto__":{"x":7}}' )
731
731
. expect ( 200 , '{"user":"tobi","__proto__":{"x":7}}' , done )
732
732
} )
733
733
734
734
it ( 'should throw when protoAction is set to error' , function ( done ) {
735
- request ( createServer ( { onProtoPoisoning : 'error' } ) )
735
+ request ( createServer ( { onProto : { onProtoPoisoning : 'error' } } ) )
736
736
. post ( '/' )
737
737
. set ( 'Content-Type' , 'application/json' )
738
738
. send ( '{"user":"tobi","__proto__":{"x":7}}' )
739
739
. expect ( 400 , '[entity.parse.failed] Object contains forbidden prototype property' , done )
740
740
} )
741
741
742
742
it ( 'should remove prototype poisoning when protoAction is set to remove' , function ( done ) {
743
- request ( createServer ( { onProtoPoisoning : 'remove' } ) )
743
+ request ( createServer ( { onProto : { onProtoPoisoning : 'remove' } } ) )
744
744
. post ( '/' )
745
745
. set ( 'Content-Type' , 'application/json' )
746
746
. send ( '{"user":"tobi","__proto__":{"x":7}}' )
747
747
. expect ( 200 , '{"user":"tobi"}' , done )
748
748
} )
749
749
} )
750
+
751
+ describe ( 'constructor poisoning' , function ( ) {
752
+ it ( 'should parse constructor when protoAction is set to ignore' , function ( done ) {
753
+ request ( createServer ( { onProto : { onConstructorPoisoning : 'ignore' } } ) )
754
+ . post ( '/' )
755
+ . set ( 'Content-Type' , 'application/json' )
756
+ . send ( '{"user":"tobi","constructor":{"prototype":{"bar":"baz"}}}' )
757
+ . expect ( 200 , '{"user":"tobi","constructor":{"prototype":{"bar":"baz"}}}' , done )
758
+ } )
759
+
760
+ it ( 'should throw when protoAction is set to error' , function ( done ) {
761
+ request ( createServer ( { onProto : { onConstructorPoisoning : 'error' } } ) )
762
+ . post ( '/' )
763
+ . set ( 'Content-Type' , 'application/json' )
764
+ . send ( '{"user":"tobi","constructor":{"prototype":{"bar":"baz"}}}' )
765
+ . expect ( 400 , '[entity.parse.failed] Object contains forbidden prototype property' , done )
766
+ } )
767
+
768
+ it ( 'should remove prototype poisoning when protoAction is set to remove' , function ( done ) {
769
+ request ( createServer ( { onProto : { onConstructorPoisoning : 'remove' } } ) )
770
+ . post ( '/' )
771
+ . set ( 'Content-Type' , 'application/json' )
772
+ . send ( '{"user":"tobi","constructor":{"prototype":{"bar":"baz"}}}' )
773
+ . expect ( 200 , '{"user":"tobi"}' , done )
774
+ } )
775
+ } )
750
776
} )
751
777
752
778
function createServer ( opts ) {
0 commit comments