Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions main/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,20 @@ export function saveWorkspace(workspace) {
}

function validateBlocklyJson(json) {
// 1. Parse JSON safely
// 1. Parse JSON safely. Reject dangerous keys via a reviver so they are
// rejected as each one is parsed, before they can ever be attached to an
// object - closing the window between JSON.parse() and the post-parse
// dangerous-key check below.
function safeReviver(key, value) {
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
throw new Error(`Dangerous property found: ${key}`);
}
return value;
}

let data;
try {
data = typeof json === 'string' ? JSON.parse(json) : json;
data = typeof json === 'string' ? JSON.parse(json, safeReviver) : json;
} catch {
throw new Error('Invalid JSON format');
}
Expand Down