Skip to content

feat: codesandbox sdk support #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

feat: codesandbox sdk support #1249

wants to merge 14 commits into from

Conversation

CompuIves
Copy link
Member

No description provided.

Copy link

codesandbox bot commented Feb 5, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Feb 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sandpack-docs ❌ Failed (Inspect) Apr 24, 2025 1:18pm
sandpack-landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2025 1:18pm
sandpack-theme ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2025 1:18pm

Copy link

codesandbox-ci bot commented Feb 5, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Comment on lines +40 to +49
const { data } = await fetch(
"https://codesandbox.io/api/v1/sandboxes/" + sandboxId,
{
method: "GET",
headers: {
Authorization: `Bearer ${globalApiKey}`,
"Content-Type": "application/json",
},
}
).then((res) => res.json());

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

The
URL
of this request depends on a
user-provided value
.

Copilot Autofix

AI about 1 month ago

To fix the issue, we need to validate and sanitize the sandboxId parameter before using it in the URL. The best approach is to enforce a strict allow-list or pattern for valid sandboxId values. For example:

  1. Use a regular expression to ensure that sandboxId only contains valid characters (e.g., alphanumeric or UUID format).
  2. Reject or sanitize any input that does not conform to the expected format.
  3. Optionally, maintain an allow-list of known valid sandboxId values if applicable.

The changes will be made in the /api/sandboxes/:id endpoint to validate the sandboxId before constructing the URL.


Suggested changeset 1
playground/server/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/playground/server/index.ts b/playground/server/index.ts
--- a/playground/server/index.ts
+++ b/playground/server/index.ts
@@ -39,2 +39,10 @@
     const sandboxId = req.params.id;
+    
+    // Validate sandboxId to ensure it is alphanumeric
+    const isValidSandboxId = /^[a-zA-Z0-9_-]+$/.test(sandboxId);
+    if (!isValidSandboxId) {
+      res.status(400).json({ error: "Invalid sandbox ID" });
+      return;
+    }
+    
     const { data } = await fetch(
EOF
@@ -39,2 +39,10 @@
const sandboxId = req.params.id;

// Validate sandboxId to ensure it is alphanumeric
const isValidSandboxId = /^[a-zA-Z0-9_-]+$/.test(sandboxId);
if (!isValidSandboxId) {
res.status(400).json({ error: "Invalid sandbox ID" });
return;
}

const { data } = await fetch(
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +116 to +126
await fetch(
`https://codesandbox.io/api/v1/sandboxes/${sandboxId}/modules/${shortid}`,
{
method: "PUT",
headers: {
Authorization: `Bearer ${globalApiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ module: { code: content } }),
}
);

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

The
URL
of this request depends on a
user-provided value
.
The
URL
of this request depends on a
user-provided value
.

Copilot Autofix

AI about 1 month ago

To fix the issue, we need to validate and sanitize the sandboxId parameter before using it in the URL. The best approach is to enforce a strict allow-list of acceptable sandboxId values or validate the format of sandboxId to ensure it adheres to expected patterns (e.g., alphanumeric strings of a specific length). This ensures that only valid and intended values are used in the outgoing request.

Steps to implement the fix:

  1. Define a validation function to check the format of sandboxId.
  2. Use this function to validate req.params.id before constructing the URL.
  3. If the validation fails, return an appropriate error response to the client.

Suggested changeset 1
playground/server/index.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/playground/server/index.ts b/playground/server/index.ts
--- a/playground/server/index.ts
+++ b/playground/server/index.ts
@@ -112,2 +112,8 @@
 
+  // Validate sandboxId to ensure it adheres to a safe format
+  const isValidSandboxId = /^[a-zA-Z0-9_-]+$/.test(sandboxId);
+  if (!isValidSandboxId) {
+    return res.status(400).json({ error: "Invalid sandbox ID format" });
+  }
+
   // Implementation details to be handled by you
EOF
@@ -112,2 +112,8 @@

// Validate sandboxId to ensure it adheres to a safe format
const isValidSandboxId = /^[a-zA-Z0-9_-]+$/.test(sandboxId);
if (!isValidSandboxId) {
return res.status(400).json({ error: "Invalid sandbox ID format" });
}

// Implementation details to be handled by you
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants