@runeya/runeya 2.0.83 → 2.0.85

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.
package/index.js CHANGED
@@ -279,7 +279,7 @@ async function main() {
279
279
  ensureNodeBinOnPath();
280
280
  await ensureUserBinsOnPath();
281
281
  if (!isPullEnv) stampConsole();
282
- const { createLocalServer, pullEnv, PullEnvError, registerInstance } = await import("./src-OHWIFAND.js");
282
+ const { createLocalServer, pullEnv, PullEnvError, registerInstance } = await import("./src-URY4IL2E.js");
283
283
  if (isPullEnv) {
284
284
  if (!serviceArg) {
285
285
  console.error("Error: --service (-s) is required with --pull-env");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeya/runeya",
3
- "version": "2.0.83",
3
+ "version": "2.0.85",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "runeya": "./index.js"
@@ -408,9 +408,20 @@ var authMiddleware = t.middleware(async ({ ctx, next }) => {
408
408
  });
409
409
  var protectedProcedure = t.procedure.use(authMiddleware);
410
410
  var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
411
- function requireLoopback(ctx) {
412
- if (!ctx.remoteAddress || !LOOPBACK.has(ctx.remoteAddress)) {
413
- throw new TRPCError({ code: "FORBIDDEN", message: "This route only answers the local machine." });
411
+ async function requireLoopbackOrToken(ctx) {
412
+ if (ctx.remoteAddress && LOOPBACK.has(ctx.remoteAddress)) return;
413
+ if (isCiMode()) return;
414
+ const authorization = ctx.authorization;
415
+ if (!authorization?.startsWith("Bearer ")) {
416
+ throw new TRPCError({
417
+ code: "FORBIDDEN",
418
+ message: "This route answers the local machine, or a signed-in app."
419
+ });
420
+ }
421
+ try {
422
+ await verifyJwt(authorization.slice(7));
423
+ } catch {
424
+ throw new TRPCError({ code: "UNAUTHORIZED", message: "Invalid or expired token" });
414
425
  }
415
426
  }
416
427
  function requireServiceAction(ctx, serviceId, action) {
@@ -603,7 +614,7 @@ var appUpdateRouter = router({
603
614
  ready: z2.boolean()
604
615
  })
605
616
  ).query(async ({ ctx }) => {
606
- requireLoopback(ctx);
617
+ await requireLoopbackOrToken(ctx);
607
618
  const npmPath = resolveNpm();
608
619
  const npmVersion = await probeVersion(npmPath, ["--version"]);
609
620
  const globalPrefix = npmVersion ? await probeVersion(npmPath, ["prefix", "-g"]) : null;
@@ -630,7 +641,7 @@ var appUpdateRouter = router({
630
641
  installedVersion: z2.string().nullable()
631
642
  })
632
643
  ).mutation(async ({ ctx }) => {
633
- requireLoopback(ctx);
644
+ await requireLoopbackOrToken(ctx);
634
645
  requireDesktop();
635
646
  const npmPath = resolveNpm();
636
647
  try {
@@ -655,8 +666,8 @@ var appUpdateRouter = router({
655
666
  * quelques instants — le démarrage réessaie déjà sur EADDRINUSE, c'est ce qui
656
667
  * rend ce relais possible sans temporisation ici.
657
668
  */
658
- restart: publicProcedure.output(z2.object({ restarting: z2.literal(true), version: z2.string() })).mutation(({ ctx }) => {
659
- requireLoopback(ctx);
669
+ restart: publicProcedure.output(z2.object({ restarting: z2.literal(true), version: z2.string() })).mutation(async ({ ctx }) => {
670
+ await requireLoopbackOrToken(ctx);
660
671
  requireDesktop();
661
672
  const child = spawn(process.execPath, process.argv.slice(1), {
662
673
  detached: true,
@@ -7702,13 +7713,23 @@ function getDeviceName() {
7702
7713
  const suffix = dir && dir !== ".runeya" ? ` \xB7 ${dir}` : "";
7703
7714
  return `${host}${suffix}`.slice(0, 64);
7704
7715
  }
7705
- function isLocalOrigin(url) {
7716
+ function callbackForReturnTo(url) {
7717
+ let parsed;
7706
7718
  try {
7707
- const { protocol, hostname: hostname2 } = new URL(url);
7708
- return (protocol === "http:" || protocol === "https:") && (hostname2 === "localhost" || hostname2 === "127.0.0.1" || hostname2 === "[::1]");
7719
+ parsed = new URL(url);
7709
7720
  } catch {
7710
- return false;
7721
+ return null;
7711
7722
  }
7723
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
7724
+ const { hostname: hostname2, port } = parsed;
7725
+ if (hostname2 === "localhost" || hostname2 === "127.0.0.1" || hostname2 === "[::1]") {
7726
+ return `http://127.0.0.1:${env.PORT}/api/cloud/callback`;
7727
+ }
7728
+ if (!env.RUNEYA_LAN_PROXY) return null;
7729
+ const effectivePort = port || (parsed.protocol === "https:" ? "443" : "80");
7730
+ if (effectivePort !== String(env.PORT)) return null;
7731
+ if (!lanIps().includes(hostname2)) return null;
7732
+ return `${parsed.origin}/api/cloud/callback`;
7712
7733
  }
7713
7734
  async function cloudFetch2(path, init = {}) {
7714
7735
  try {
@@ -7727,11 +7748,14 @@ function isAllowedProxyPath(path) {
7727
7748
  var cloudAuthRouter = router({
7728
7749
  /** Build the cloud authorization URL to open in the browser. */
7729
7750
  startLogin: protectedProcedure.input(z16.object({ returnTo: z16.string().url().max(2048) })).mutation(async ({ input }) => {
7730
- if (!isLocalOrigin(input.returnTo)) {
7731
- throw new TRPCError11({ code: "BAD_REQUEST", message: "returnTo must be a local origin." });
7751
+ const callback = callbackForReturnTo(input.returnTo);
7752
+ if (!callback) {
7753
+ throw new TRPCError11({
7754
+ code: "BAD_REQUEST",
7755
+ message: env.RUNEYA_LAN_PROXY ? "returnTo must be this machine, on the server port." : "returnTo must be a local origin."
7756
+ });
7732
7757
  }
7733
7758
  const state = cloudSessionStore.createState(input.returnTo);
7734
- const callback = `http://127.0.0.1:${env.PORT}/api/cloud/callback`;
7735
7759
  const url = `${getCloudAppUrl()}/link-local?callback=${encodeURIComponent(callback)}&state=${encodeURIComponent(state)}`;
7736
7760
  return { url };
7737
7761
  }),
@@ -18253,4 +18277,4 @@ export {
18253
18277
  pullEnv,
18254
18278
  registerInstance
18255
18279
  };
18256
- //# sourceMappingURL=src-OHWIFAND.js.map
18280
+ //# sourceMappingURL=src-URY4IL2E.js.map