Skip to content

Commit ba10cc1

Browse files
author
Cindy Zhao
committed
fix:validate region from url params to prevent xss attack
1 parent 78bb728 commit ba10cc1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

patched-vscode/extensions/sagemaker-open-notebook-extension/src/extension.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@ export function activate() {
1717

1818
}
1919

20+
function isValidRegion(region: string): boolean {
21+
// This regex allows for characters, numbers, and hyphens
22+
const regionRegex = /^[a-zA-Z0-9-]+$/;
23+
return regionRegex.test(region);
24+
}
25+
2026
async function loadAndDisplayNotebook(fileKey: string, clusterId: string, region: string) {
27+
if (!isValidRegion(region)) {
28+
vscode.window.showErrorMessage('Invalid region format. Region should only contain characters, numbers, and hyphens.');
29+
return;
30+
}
31+
2132
const bucketName = `jumpstart-cache-prod-${region}`;
2233
const url = `https://${bucketName}.s3.${region}.amazonaws.com/${fileKey}`;
2334
try {

patches/sagemaker-open-notebook-extension.patch

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-open-notebook-extension
162162
===================================================================
163163
--- /dev/null
164164
+++ sagemaker-code-editor/vscode/extensions/sagemaker-open-notebook-extension/src/extension.ts
165-
@@ -0,0 +1,89 @@
165+
@@ -0,0 +1,91 @@
166166
+
167167
+import * as vscode from 'vscode';
168168
+import * as https from 'https';
@@ -182,7 +182,18 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-open-notebook-extension
182182
+
183183
+}
184184
+
185+
+function isValidRegion(region: string): boolean {
186+
+ // This regex allows for characters, numbers, and hyphens
187+
+ const regionRegex = /^[a-zA-Z0-9-]+$/;
188+
+ return regionRegex.test(region);
189+
+}
190+
+
185191
+async function loadAndDisplayNotebook(fileKey: string, clusterId: string, region: string) {
192+
+ if (!isValidRegion(region)) {
193+
+ vscode.window.showErrorMessage('Invalid region format. Region should only contain characters, numbers, and hyphens.');
194+
+ return;
195+
+ }
196+
+
186197
+ const bucketName = `jumpstart-cache-prod-${region}`;
187198
+ const url = `https://${bucketName}.s3.${region}.amazonaws.com/${fileKey}`;
188199
+ try {

0 commit comments

Comments
 (0)