File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - [ utils] ref: Update wrap method to hide internal sentry flags
6+ - [ utils] fix: Make internal Sentry flags non-enumerable in fill util
7+
58## 4.5.3
69
710- [ browser] : fix: Fix UnhandledPromise: [ object Object]
Original file line number Diff line number Diff line change @@ -113,13 +113,26 @@ export function wrap(
113113 }
114114 } catch ( _oO ) { } // tslint:disable-line:no-empty
115115
116+ fn . prototype = fn . prototype || { } ;
116117 sentryWrapped . prototype = fn . prototype ;
117- fn . __sentry_wrapped__ = sentryWrapped ;
118+
119+ Object . defineProperty ( fn , '__sentry_wrapped__' , {
120+ enumerable : false ,
121+ value : sentryWrapped ,
122+ } ) ;
118123
119124 // Signal that this function has been wrapped/filled already
120125 // for both debugging and to prevent it to being wrapped/filled twice
121- sentryWrapped . __sentry__ = true ;
122- sentryWrapped . __sentry_original__ = fn ;
126+ Object . defineProperties ( sentryWrapped , {
127+ __sentry__ : {
128+ enumerable : false ,
129+ value : true ,
130+ } ,
131+ __sentry_original__ : {
132+ enumerable : false ,
133+ value : fn ,
134+ } ,
135+ } ) ;
123136
124137 return sentryWrapped ;
125138}
Original file line number Diff line number Diff line change @@ -179,4 +179,21 @@ describe('wrap()', () => {
179179 expect ( error . message ) . equal ( 'boom' ) ;
180180 }
181181 } ) ;
182+
183+ it ( 'internal flags shouldnt be enumerable' , ( ) => {
184+ const fn = ( ( ) => 1337 ) as SentryWrappedFunction ;
185+ const wrapped = wrap ( fn ) ;
186+
187+ // Shouldn't show up in iteration
188+ expect ( Object . keys ( fn ) ) . to . not . include ( '__sentry__' ) ;
189+ expect ( Object . keys ( fn ) ) . to . not . include ( '__sentry_original__' ) ;
190+ expect ( Object . keys ( fn ) ) . to . not . include ( '__sentry_wrapped__' ) ;
191+ expect ( Object . keys ( wrapped ) ) . to . not . include ( '__sentry__' ) ;
192+ expect ( Object . keys ( wrapped ) ) . to . not . include ( '__sentry_original__' ) ;
193+ expect ( Object . keys ( wrapped ) ) . to . not . include ( '__sentry_wrapped__' ) ;
194+ // But should be accessible directly
195+ expect ( wrapped . __sentry__ ) . to . equal ( true ) ;
196+ expect ( wrapped . __sentry_original__ ) . to . equal ( fn ) ;
197+ expect ( fn . __sentry_wrapped__ ) . to . equal ( wrapped ) ;
198+ } ) ;
182199} ) ;
You can’t perform that action at this time.
0 commit comments