File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 const runtime = Scratch . vm . runtime ;
1616
1717 let hideFromPalette = true ;
18+
19+ /** @type {Record<string, {TYPE?: string; DATA?: unknown; URL?: string;}> } */
1820 let webhooks ;
21+
1922 function setupStorage ( ) {
20- if ( ! runtime . extensionStorage [ "cubesterWebhooks" ] ) {
21- runtime . extensionStorage [ "cubesterWebhooks" ] = {
22- webhooks : Object . create ( null ) ,
23- } ;
23+ const safe = Object . create ( null ) ;
24+
25+ // We always want to rebuild storage as an object with null prototype to prevent pollution attacks later.
26+ const existing = runtime . extensionStorage [ "cubesterWebhooks" ] ;
27+ if (
28+ existing &&
29+ typeof existing === "object" &&
30+ existing . webhooks &&
31+ typeof existing . webhooks === "object"
32+ ) {
33+ for ( const key of Object . keys ( existing . webhooks ) ) {
34+ const entry = existing . webhooks [ key ] ;
35+ // Everything later assumes this is a real object, so we should verify
36+ if ( entry && typeof entry === "object" ) {
37+ safe [ key ] = entry ;
38+ }
39+ }
2440 }
25- webhooks = runtime . extensionStorage [ "cubesterWebhooks" ] . webhooks ;
26- if ( Object . keys ( webhooks ) . length > 0 ) {
41+
42+ runtime . extensionStorage [ "cubesterWebhooks" ] = {
43+ webhooks : safe
44+ } ;
45+ webhooks = safe ;
46+
47+ if ( hideFromPalette && Object . keys ( webhooks ) . length > 0 ) {
2748 hideFromPalette = false ;
49+ runtime . extensionManager . refreshBlocks ( ) ;
2850 }
2951 }
52+
3053 setupStorage ( ) ;
3154 runtime . on ( "PROJECT_LOADED" , setupStorage ) ;
3255
You can’t perform that action at this time.
0 commit comments