Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Use base64 to solve security stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
noamzaks committed Jun 23, 2024
1 parent 524e6e1 commit 128f6f3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions addons/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
state = state.replace("preview-arg:state:", "");
/// Set it later when acquiring the VSCode API
window.vscode_state = JSON.parse(state);
window.vscode_state.fsPath = atob(window.vscode_state.fsPath);
}

/// https://stackoverflow.com/questions/13586999/color-difference-similarity-between-two-values-with-js
Expand Down
3 changes: 1 addition & 2 deletions addons/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ const launchPreview = async (task: LaunchInBrowserTask | LaunchInWebViewTask) =>
html = html.replace(
"preview-arg:previewMode:Doc",
`preview-arg:previewMode:${previewMode}`
).replace("preview-arg:state:{}", `preview-arg:state:${JSON.stringify({ mode: task.mode, fsPath: bindDocument.uri.fsPath.replace(/`/g, "\\`") })}`);
// Replace all the backticks here ^ to avoid the backtick "escaping" the string in the JS itself and executing other code.
).replace("preview-arg:state:{}", `preview-arg:state:${JSON.stringify({ mode: task.mode, fsPath: Buffer.from(bindDocument.uri.fsPath).toString("base64") })}`);

panel.webview.html = html.replace("ws://127.0.0.1:23625", `ws://127.0.0.1:${dataPlanePort}`);
// 虽然配置的是 http,但是如果是桌面客户端,任何 tcp 连接都支持,这也就包括了 ws
Expand Down

0 comments on commit 128f6f3

Please sign in to comment.