Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/sandboxes/getSandboxEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@ export function getSandboxEnv(
env.GITHUB_TOKEN = githubToken;
}

const chartmetricRefreshToken = process.env.CHARTMETRIC_REFRESH_TOKEN;
if (chartmetricRefreshToken) {
env.CHARTMETRIC_REFRESH_TOKEN = chartmetricRefreshToken;
}
Comment on lines +23 to +26
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Validate CHARTMETRIC_REFRESH_TOKEN through a Zod env schema before use.

Line 23 reads from process.env directly; this bypasses the repo’s schema-validation requirement for TS sources. Please parse env once (e.g., with a Zod schema) and build env from parsed output.

Suggested refactor
+import { z } from "zod";
+
+const SandboxEnvSchema = z.object({
+  RECOUP_API_KEY: z.string().min(1),
+  GITHUB_TOKEN: z.string().min(1).optional(),
+  CHARTMETRIC_REFRESH_TOKEN: z.string().min(1).optional(),
+});
+
 export function getSandboxEnv(
   accountId: string
 ): Record<string, string> {
-  const apiKey = process.env.RECOUP_API_KEY;
+  const parsedEnv = SandboxEnvSchema.parse(process.env);
+  const apiKey = parsedEnv.RECOUP_API_KEY;
   if (!apiKey) {
     throw new Error("Missing RECOUP_API_KEY environment variable");
   }
@@
-  const githubToken = process.env.GITHUB_TOKEN;
+  const githubToken = parsedEnv.GITHUB_TOKEN;
@@
-  const chartmetricRefreshToken = process.env.CHARTMETRIC_REFRESH_TOKEN;
+  const chartmetricRefreshToken = parsedEnv.CHARTMETRIC_REFRESH_TOKEN;

As per coding guidelines, Use Zod for schema validation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/getSandboxEnv.ts` around lines 23 - 26, Replace the direct read
of process.env.CHARTMETRIC_REFRESH_TOKEN in getSandboxEnv.ts with a
Zod-validated parse: define a Zod schema (e.g., SandboxEnvSchema) that includes
CHARTMETRIC_REFRESH_TOKEN as a string (optional or required per spec), call
SandboxEnvSchema.parse(process.env) (or safeParse and handle errors) to produce
parsedEnv, and then set env.CHARTMETRIC_REFRESH_TOKEN =
parsedEnv.CHARTMETRIC_REFRESH_TOKEN; update any related code to use the parsed
object instead of raw process.env. Ensure you reference SandboxEnvSchema and
parsedEnv in the change and handle validation failures consistently with the
repo’s error handling.


return env;
}
3 changes: 3 additions & 0 deletions src/sandboxes/setupOpenClaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export async function setupOpenClaw(
}

const githubToken = process.env.GITHUB_TOKEN;
const chartmetricRefreshToken = process.env.CHARTMETRIC_REFRESH_TOKEN;

logger.log("Injecting env vars into openclaw.json", {
RECOUP_API_KEY: `${process.env.RECOUP_API_KEY.slice(0, 4)}...`,
RECOUP_ACCOUNT_ID: accountId,
GITHUB_TOKEN: githubToken ? "present" : "missing",
CHARTMETRIC_REFRESH_TOKEN: chartmetricRefreshToken ? "present" : "missing",
});

const injectEnv = await sandbox.runCommand({
Expand All @@ -43,6 +45,7 @@ export async function setupOpenClaw(
c.env.RECOUP_API_KEY = '${process.env.RECOUP_API_KEY}';
c.env.RECOUP_ACCOUNT_ID = '${accountId}';
${githubToken ? `c.env.GITHUB_TOKEN = '${githubToken}';` : ""}
${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = '${chartmetricRefreshToken}';` : ""}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Escape token values before embedding into the node -e script.

Line 48 interpolates a raw secret inside a quoted JS snippet. A token containing quote/escape characters can break command generation and opens an injection risk. Use JSON.stringify(...) for assignment literals.

Safer assignment serialization
-        ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = '${chartmetricRefreshToken}';` : ""}
+        ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = ${JSON.stringify(chartmetricRefreshToken)};` : ""}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = '${chartmetricRefreshToken}';` : ""}
${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = ${JSON.stringify(chartmetricRefreshToken)};` : ""}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/setupOpenClaw.ts` at line 48, The template is interpolating raw
secret text into the generated `node -e` script (the `chartmetricRefreshToken`
insertion in src/sandboxes/setupOpenClaw.ts), which can break quoting or allow
injection; update the template to serialize the token value with a safe JS
literal encoder (e.g., use JSON.stringify(chartmetricRefreshToken) when building
the `c.env.CHARTMETRIC_REFRESH_TOKEN = ...` assignment) so the embedded value is
properly escaped and quoted before insertion into the `node -e` script.

c.tools = c.tools || {};
c.tools.profile = 'coding';
c.agents = c.agents || {};
Expand Down
Loading