@@ -701,4 +701,106 @@ describe('Processing', function() {
701
701
702
702
} ) ;
703
703
704
+ describe ( 'Avoid a prototype pollution vulnerability' , function ( ) {
705
+
706
+ describe ( 'The critical property key is in a src object' , function ( ) {
707
+
708
+ it ( 'should ignore a property key: __proto__' , function ( done ) {
709
+ var maliciousSrcJson = '{"__proto__":{"polluted":"polluted"},"a":1}' ;
710
+ expect ( { } . polluted ) . to . be . undefined ;
711
+ expect ( copyProps ( JSON . parse ( maliciousSrcJson ) , { } ) ) . to . deep . equal ( { a : 1 } ) ;
712
+ expect ( { } . polluted ) . to . be . undefined ;
713
+ done ( ) ;
714
+ } ) ;
715
+
716
+ it ( 'should ignore a property key: constructor.prototype' , function ( done ) {
717
+ var maliciousSrcJson = '{"constructor":{"prototype":{"polluted":"polluted"}},"a":1}' ;
718
+ expect ( { } . polluted ) . to . be . undefined ;
719
+ expect ( copyProps ( JSON . parse ( maliciousSrcJson ) , { } ) ) . to . deep . equal ( { a : 1 } ) ;
720
+ expect ( { } . polluted ) . to . be . undefined ;
721
+ done ( ) ;
722
+ } ) ;
723
+
724
+ } ) ;
725
+
726
+ describe ( 'The critical property key is in a dest object and using reverse' , function ( ) {
727
+
728
+ it ( 'should ignore a property key: __proto__' , function ( done ) {
729
+ var maliciousSrcJson = '{"__proto__":{"polluted":"polluted"},"a":1}' ;
730
+ expect ( { } . polluted ) . to . be . undefined ;
731
+ expect ( copyProps ( { } , JSON . parse ( maliciousSrcJson ) , true ) ) . to . deep . equal ( { a : 1 } ) ;
732
+ expect ( { } . polluted ) . to . be . undefined ;
733
+ done ( ) ;
734
+ } ) ;
735
+
736
+ it ( 'should ignore a property key: constructor.prototype' , function ( done ) {
737
+ var maliciousSrcJson = '{"constructor":{"prototype":{"polluted":"polluted"}},"a":1}' ;
738
+ expect ( { } . polluted ) . to . be . undefined ;
739
+ expect ( copyProps ( { } , JSON . parse ( maliciousSrcJson ) , true ) ) . to . deep . equal ( { a : 1 } ) ;
740
+ expect ( { } . polluted ) . to . be . undefined ;
741
+ done ( ) ;
742
+ } ) ;
743
+
744
+ } ) ;
745
+
746
+ describe ( 'The critical property value is in a fromto object' , function ( ) {
747
+
748
+ it ( 'should ignore a property value: __proto__' , function ( done ) {
749
+ var fromto = { a : '__proto__.poluuted' , b : 'c' } ;
750
+ expect ( { } . polluted ) . to . be . undefined ;
751
+ expect ( copyProps ( { a : 'polluted' , b : 1 } , { } , fromto ) ) . to . deep . equal ( { c : 1 } ) ;
752
+ expect ( { } . polluted ) . to . be . undefined ;
753
+ done ( ) ;
754
+ } ) ;
755
+
756
+ it ( 'should ignore a property value: constructor.prototype' , function ( done ) {
757
+ var fromto = { a : 'constructor.prototype.polluted' , b : 'c' } ;
758
+ expect ( { } . polluted ) . to . be . undefined ;
759
+ expect ( copyProps ( { a : 'polluted' , b : 1 } , { } , fromto ) ) . to . deep . equal ( { c : 1 } ) ;
760
+ expect ( { } . polluted ) . to . be . undefined ;
761
+ done ( ) ;
762
+ } ) ;
763
+
764
+ } ) ;
765
+
766
+ describe ( 'The critical property key is in a fromto object and using reverse' , function ( ) {
767
+
768
+ it ( 'should ignore a property key: __proto__' , function ( done ) {
769
+ var fromto = { '__proto__.poluuted' : 'a' , c : 'b' } ;
770
+ expect ( { } . polluted ) . to . be . undefined ;
771
+ expect ( copyProps ( { } , { a : 'polluted' , b : 1 } , fromto , true ) ) . to . deep . equal ( { c : 1 } ) ;
772
+ expect ( { } . polluted ) . to . be . undefined ;
773
+ done ( ) ;
774
+ } ) ;
775
+
776
+ it ( 'should ignore a property key: constructor.prototype and using reverse' , function ( done ) {
777
+ var fromto = { 'constructor.prototype.polluted' : 'a' , c : 'b' } ;
778
+ expect ( { } . polluted ) . to . be . undefined ;
779
+ expect ( copyProps ( { } , { a : 'polluted' , b : 1 } , fromto , true ) ) . to . deep . equal ( { c : 1 } ) ;
780
+ expect ( { } . polluted ) . to . be . undefined ;
781
+ done ( ) ;
782
+ } ) ;
783
+
784
+ } ) ;
785
+
786
+ describe ( 'The critical element is in a fromto array' , function ( ) {
787
+
788
+ it ( 'should ignore an element: __proto__' , function ( done ) {
789
+ var fromto = [ '__proto__.polluted' , 'b' ] ;
790
+ expect ( { } . polluted ) . to . be . undefined ;
791
+ expect ( copyProps ( JSON . parse ( '{"__proto__":{"polluted":"polluted"},"b":1}' ) , { } , fromto ) ) . to . deep . equal ( { b : 1 } ) ;
792
+ expect ( { } . polluted ) . to . be . undefined ;
793
+ done ( ) ;
794
+ } ) ;
795
+
796
+ it ( 'should ignore an element: constructor.prototype' , function ( done ) {
797
+ var fromto = [ 'constructor.prototype.polluted' , 'b' ] ;
798
+ expect ( { } . polluted ) . to . be . undefined ;
799
+ expect ( copyProps ( JSON . parse ( '{"constructor":{"prototype":{"polluted":"polluted"}},"b":1}' ) , { } , fromto ) ) . to . deep . equal ( { b : 1 } ) ;
800
+ expect ( { } . polluted ) . to . be . undefined ;
801
+ done ( ) ;
802
+ } ) ;
803
+
804
+ } ) ;
805
+ } ) ;
704
806
} ) ;
0 commit comments