@byoky/openclaw-plugin 0.3.0 → 0.4.1

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -293,17 +293,7 @@ async function startCallbackServer(ctx, requestProviderId) {
293
293
  return new Promise((resolve) => {
294
294
  let resolved = false;
295
295
  const server = createServer((req, res) => {
296
- const reqOrigin = req.headers.origin || "";
297
- let isLocalhost = false;
298
- try {
299
- const parsed = new URL(reqOrigin);
300
- isLocalhost = parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost";
301
- } catch {
302
- }
303
- res.setHeader(
304
- "Access-Control-Allow-Origin",
305
- isLocalhost ? reqOrigin : "http://127.0.0.1"
306
- );
296
+ res.setHeader("Access-Control-Allow-Origin", "http://127.0.0.1");
307
297
  res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
308
298
  res.setHeader("Access-Control-Allow-Headers", "Content-Type");
309
299
  if (req.method === "OPTIONS") {
@@ -312,11 +302,22 @@ async function startCallbackServer(ctx, requestProviderId) {
312
302
  return;
313
303
  }
314
304
  if (req.method === "POST" && req.url === "/callback") {
305
+ const MAX_BODY_SIZE = 1048576;
315
306
  let body = "";
307
+ let oversized = false;
316
308
  req.on("data", (chunk) => {
317
309
  body += chunk.toString();
310
+ if (body.length > MAX_BODY_SIZE) {
311
+ oversized = true;
312
+ req.destroy();
313
+ }
318
314
  });
319
315
  req.on("end", () => {
316
+ if (oversized) {
317
+ res.writeHead(413);
318
+ res.end("Request body too large");
319
+ return;
320
+ }
320
321
  try {
321
322
  const data = JSON.parse(body);
322
323
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -324,8 +325,8 @@ async function startCallbackServer(ctx, requestProviderId) {
324
325
  if (!resolved) {
325
326
  resolved = true;
326
327
  resolve({
327
- providers: data.providers || [],
328
- port: data.bridgePort || DEFAULT_BRIDGE_PORT,
328
+ providers: Array.isArray(data.providers) ? data.providers : [],
329
+ port: typeof data.bridgePort === "number" ? data.bridgePort : DEFAULT_BRIDGE_PORT,
329
330
  server
330
331
  });
331
332
  }
@@ -429,7 +430,7 @@ function buildAuthPage(requestProviderId) {
429
430
  id: requestId,
430
431
  requestId,
431
432
  payload: { providers: ${providerFilter} },
432
- }, '*');
433
+ }, window.location.origin);
433
434
 
434
435
  const response = await new Promise((resolve, reject) => {
435
436
  function handler(event) {
@@ -461,7 +462,7 @@ function buildAuthPage(requestProviderId) {
461
462
  requestId: bridgeRequestId,
462
463
  action: 'startBridgeProxy',
463
464
  payload: { sessionKey: response.sessionKey, port: ${DEFAULT_BRIDGE_PORT} },
464
- }, '*');
465
+ }, window.location.origin);
465
466
 
466
467
  const bridgeResult = await new Promise((resolve, reject) => {
467
468
  function handler(event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byoky/openclaw-plugin",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Byoky wallet provider plugin for OpenClaw — manage AI API keys from your browser wallet",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",