33 */
44
55import { describe , expect , test , vi } from 'vitest' ;
6- import { addNonEnumerableProperty , normalize } from '../../../src' ;
6+ import { normalize , setNormalizationDepthOverrideHint , setSkipNormalizationHint } from '../../../src' ;
77import * as isModule from '../../../src/utils/is' ;
88import * as stacktraceModule from '../../../src/utils/stacktrace' ;
99
@@ -655,15 +655,36 @@ describe('normalize()', () => {
655655 } ) ;
656656 } ) ;
657657
658- describe ( 'skips normalizing objects marked with a non-enumerable property __sentry_skip_normalization__' , ( ) => {
658+ describe ( 'regression: JSON cannot spoof skip-normalization via string keys' , ( ) => {
659+ test ( '__sentry_skip_normalization__ as an own string property is still normalized' , ( ) => {
660+ function someFun ( ) : void {
661+ /* no-empty */
662+ }
663+ const jsonLikePayload = {
664+ __sentry_skip_normalization__ : true ,
665+ nan : NaN ,
666+ fun : someFun ,
667+ } ;
668+
669+ const result = normalize ( jsonLikePayload ) ;
670+
671+ expect ( result ) . toEqual ( {
672+ __sentry_skip_normalization__ : true ,
673+ nan : '[NaN]' ,
674+ fun : '[Function: someFun]' ,
675+ } ) ;
676+ } ) ;
677+ } ) ;
678+
679+ describe ( 'skips normalizing objects marked with setSkipNormalizationHint (internal symbol)' , ( ) => {
659680 test ( 'by leaving non-serializable values intact' , ( ) => {
660681 const someFun = ( ) => undefined ;
661682 const alreadyNormalizedObj = {
662683 nan : NaN ,
663684 fun : someFun ,
664685 } ;
665686
666- addNonEnumerableProperty ( alreadyNormalizedObj , '__sentry_skip_normalization__' , true ) ;
687+ setSkipNormalizationHint ( alreadyNormalizedObj ) ;
667688
668689 const result = normalize ( alreadyNormalizedObj ) ;
669690 expect ( result ) . toEqual ( {
@@ -681,7 +702,7 @@ describe('normalize()', () => {
681702 } ,
682703 } ;
683704
684- addNonEnumerableProperty ( alreadyNormalizedObj , '__sentry_skip_normalization__' , true ) ;
705+ setSkipNormalizationHint ( alreadyNormalizedObj ) ;
685706
686707 const obj = {
687708 foo : {
@@ -703,7 +724,7 @@ describe('normalize()', () => {
703724 } ) ;
704725 } ) ;
705726
706- describe ( 'overrides normalization depth with a non-enumerable property __sentry_override_normalization_depth__ ' , ( ) => {
727+ describe ( 'overrides normalization depth with setNormalizationDepthOverrideHint ' , ( ) => {
707728 test ( 'by increasing depth if it is higher' , ( ) => {
708729 const normalizationTarget = {
709730 foo : 'bar' ,
@@ -717,7 +738,7 @@ describe('normalize()', () => {
717738 } ,
718739 } ;
719740
720- addNonEnumerableProperty ( normalizationTarget , '__sentry_override_normalization_depth__' , 3 ) ;
741+ setNormalizationDepthOverrideHint ( normalizationTarget , 3 ) ;
721742
722743 const result = normalize ( normalizationTarget , 1 ) ;
723744
@@ -745,7 +766,7 @@ describe('normalize()', () => {
745766 } ,
746767 } ;
747768
748- addNonEnumerableProperty ( normalizationTarget , '__sentry_override_normalization_depth__' , 1 ) ;
769+ setNormalizationDepthOverrideHint ( normalizationTarget , 1 ) ;
749770
750771 const result = normalize ( normalizationTarget , 3 ) ;
751772
0 commit comments