Skip to content

Commit 84335e0

Browse files
aditya520claude
andcommitted
fix(dev-hub): redact user API key from playground code snippets
The generated code samples interpolated config.accessToken directly into the Monaco editor, which leaked the user's key on video calls and screenshares even though the input uses type="password". Rewrite each generator to read the key from an env var (LAZER_TOKEN) instead — same pattern the rest of the monorepo uses. The Run button still authenticates through the server proxy using React state, so end-to-end streaming is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2ecd0a2 commit 84335e0

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

apps/developer-hub/src/components/Playground/CodeGenerators/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { PlaygroundConfig } from "../types";
44
* Generates CLI code using wscat for WebSocket connections
55
*/
66
export function generateCliCode(config: PlaygroundConfig): string {
7-
// If accessToken is empty, use demo token placeholder
8-
const token = config.accessToken.trim() || "DEMO_TOKEN";
97
const priceFeedIds =
108
config.priceFeedIds.length > 0 ? config.priceFeedIds : [1, 2];
119
const properties =
@@ -30,10 +28,12 @@ export function generateCliCode(config: PlaygroundConfig): string {
3028
return `# Install wscat if not already installed
3129
npm install -g wscat
3230
31+
# Export your API key so it never ends up in shell history or version control
32+
export LAZER_TOKEN="your-api-key-here"
33+
3334
# Connect to Pyth Lazer WebSocket with authentication
34-
# Replace YOUR_ACCESS_TOKEN with your actual token
3535
wscat -c "wss://pyth-lazer-0.dourolabs.app/v1/stream" \\
36-
-H "Authorization: Bearer ${token}"
36+
-H "Authorization: Bearer $LAZER_TOKEN"
3737
3838
# Once connected, send this subscription message:
3939
${payloadStr}
@@ -42,7 +42,7 @@ ${payloadStr}
4242
4343
# Alternative: Using curl for one-shot requests (HTTP API)
4444
curl -X POST "https://pyth-lazer-0.dourolabs.app/v1/latest_price" \\
45-
-H "Authorization: Bearer ${token}" \\
45+
-H "Authorization: Bearer $LAZER_TOKEN" \\
4646
-H "Content-Type: application/json" \\
4747
-d '${JSON.stringify({ formats, parsed: config.parsed, priceFeedIds, properties })}'
4848

apps/developer-hub/src/components/Playground/CodeGenerators/go.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { PlaygroundConfig } from "../types";
44
* Generates Go code using gorilla/websocket for WebSocket connections
55
*/
66
export function generateGoCode(config: PlaygroundConfig): string {
7-
// If accessToken is empty, use demo token placeholder
8-
const token = config.accessToken.trim() || "DEMO_TOKEN";
97
const priceFeedIds =
108
config.priceFeedIds.length > 0 ? config.priceFeedIds : [1, 2];
119
const properties =
@@ -82,7 +80,11 @@ func main() {
8280
"wss://pyth-lazer-2.dourolabs.app/v1/stream",
8381
}
8482
85-
token := "${token}"
83+
// Read your API key from the environment (never hard-code it)
84+
token := os.Getenv("LAZER_TOKEN")
85+
if token == "" {
86+
log.Fatal("Set LAZER_TOKEN in your environment")
87+
}
8688
8789
// Set up interrupt handler
8890
interrupt := make(chan os.Signal, 1)

apps/developer-hub/src/components/Playground/CodeGenerators/python.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { PlaygroundConfig } from "../types";
44
* Generates Python code using websockets library
55
*/
66
export function generatePythonCode(config: PlaygroundConfig): string {
7-
// If accessToken is empty, use demo token placeholder
8-
const token = config.accessToken.trim() || "DEMO_TOKEN";
97
const priceFeedIds =
108
config.priceFeedIds.length > 0 ? config.priceFeedIds : [1, 2];
119
const properties =
@@ -32,6 +30,7 @@ Usage:
3230
3331
import asyncio
3432
import json
33+
import os
3534
import signal
3635
from typing import Any
3736
@@ -42,8 +41,8 @@ except ImportError:
4241
exit(1)
4342
4443
45-
# Configuration
46-
TOKEN = "${token}"
44+
# Read your API key from the environment (never hard-code it)
45+
TOKEN = os.environ["LAZER_TOKEN"]
4746
ENDPOINTS = [
4847
"wss://pyth-lazer-0.dourolabs.app/v1/stream",
4948
"wss://pyth-lazer-1.dourolabs.app/v1/stream",

apps/developer-hub/src/components/Playground/CodeGenerators/typescript.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { PlaygroundConfig } from "../types";
44
* Generates TypeScript code using the pyth-lazer-sdk package
55
*/
66
export function generateTypeScriptCode(config: PlaygroundConfig): string {
7-
// If accessToken is empty, use demo token placeholder
8-
const token = config.accessToken.trim() || "DEMO_TOKEN";
97
const priceFeedIds =
108
config.priceFeedIds.length > 0 ? config.priceFeedIds : [1, 2];
119
const properties =
@@ -19,9 +17,13 @@ export function generateTypeScriptCode(config: PlaygroundConfig): string {
1917

2018
return `import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
2119
20+
// Read your API key from the environment (never hard-code it)
21+
const token = process.env.LAZER_TOKEN;
22+
if (!token) throw new Error("Set LAZER_TOKEN in your environment");
23+
2224
// Create the Pyth Lazer client with WebSocket pool configuration
2325
const client = await PythLazerClient.create({
24-
token: "${token}",
26+
token,
2527
webSocketPoolConfig: {
2628
urls: [
2729
"wss://pyth-lazer-0.dourolabs.app/v1/stream",

0 commit comments

Comments
 (0)