rwsdk 1.0.0-beta.38 → 1.0.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,12 @@ export const defineApp = (routes) => {
26
26
  }
27
27
  else if (import.meta.env.VITE_IS_DEV_SERVER &&
28
28
  new URL(request.url).pathname === "/__worker-run") {
29
+ const expectedToken = import.meta.env
30
+ .VITE_RWSDK_WORKER_RUN_TOKEN;
31
+ const requestToken = request.headers.get("x-rwsdk-worker-run-token");
32
+ if (!expectedToken || expectedToken !== requestToken) {
33
+ return new Response("Forbidden", { status: 403 });
34
+ }
29
35
  const url = new URL(request.url);
30
36
  const scriptPath = url.searchParams.get("script");
31
37
  if (!scriptPath) {
@@ -1,3 +1,4 @@
1
+ import crypto from "crypto";
1
2
  import dbg from "debug";
2
3
  import getPort from "get-port";
3
4
  import path from "path";
@@ -7,6 +8,8 @@ import { createLogger } from "vite";
7
8
  const debug = dbg("rwsdk:worker-run");
8
9
  const main = async () => {
9
10
  process.env.RWSDK_WORKER_RUN = "1";
11
+ const token = crypto.randomBytes(32).toString("hex");
12
+ process.env.VITE_RWSDK_WORKER_RUN_TOKEN = token;
10
13
  const relativeScriptPath = process.argv[2];
11
14
  if (!relativeScriptPath) {
12
15
  console.error("Error: Script path is required");
@@ -46,7 +49,11 @@ const main = async () => {
46
49
  const fileUrl = pathToFileURL(scriptPath).href;
47
50
  const url = `http://localhost:${port}/__worker-run?script=${encodeURIComponent(fileUrl)}`;
48
51
  debug("Fetching %s", url);
49
- const response = await fetch(url);
52
+ const response = await fetch(url, {
53
+ headers: {
54
+ "x-rwsdk-worker-run-token": token,
55
+ },
56
+ });
50
57
  debug("Response from worker: %s", response);
51
58
  if (!response.ok) {
52
59
  const errorText = await response.text();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "1.0.0-beta.38",
3
+ "version": "1.0.0-beta.39",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {