Skip to content

Commit cda21d5

Browse files
authored
CubesterYT/Webhooks: fix two bugs (#2505)
- a maybe security thing? - and fix the block list not reliably refreshing when you go from empty project in editor -> import project
1 parent 7e6e608 commit cda21d5

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

extensions/CubesterYT/Webhooks.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,41 @@
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

0 commit comments

Comments
 (0)