miqro 7.3.2 → 7.3.4

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.
@@ -18,13 +18,15 @@ export default {
18
18
  const cookieToken = args.req.cookies[ADMIN_EDITOR_AUTH_COOKIE];
19
19
  //console.log("\n\nqueryToken[%s] cookieToken[%s] KEY[%s]\n\n", queryToken, cookieToken, KEY);
20
20
  if (queryToken) {
21
- if (typeof queryToken === "string" && timingSafeEqual(Buffer.from(queryToken), Buffer.from(KEY))) {
21
+ const queryBuf = Buffer.from(String(queryToken));
22
+ const keyBuf = Buffer.from(KEY);
23
+ if (typeof queryToken === "string" && queryBuf.length === keyBuf.length && timingSafeEqual(queryBuf, keyBuf)) {
22
24
  args.res.setCookie(ADMIN_EDITOR_AUTH_COOKIE, KEY, {
23
- expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 31 * 12 * 500),
25
+ expires: new Date(Date.now() + 1000 * 60 * 60 * 24),
24
26
  httpOnly: true,
25
- //secure: true,
27
+ //secure: args.req.secure,
28
+ sameSite: "strict",
26
29
  path: "/",
27
- //sameSite: "strict"
28
30
  });
29
31
  args.req.searchParams.delete(ADMIN_EDITOR_AUTH_QUERY);
30
32
  const queryString = args.req.searchParams.toString();
File without changes
@@ -59,6 +59,7 @@ export async function esBuild(options, logger) {
59
59
  else {
60
60
  exec(esBuildCMD, {
61
61
  maxBuffer: 1024 * 1000 * 2000,
62
+ timeout: 60000,
62
63
  cwd: dirname(options.entryPoints[0])
63
64
  }, (err, stdout, _stderr) => {
64
65
  if (err) {
@@ -47,7 +47,7 @@ export function setupExitHandlers(app) {
47
47
  }
48
48
  process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
49
49
  });
50
- process.on('exit', async function (code) {
50
+ process.on('exit', function (code) {
51
51
  if (exceptionOccured) {
52
52
  app.logger?.error('Exception occured');
53
53
  }
@@ -60,7 +60,7 @@ export function setupExitHandlers(app) {
60
60
  }*/
61
61
  cleanJSX(app);
62
62
  if (app.server) {
63
- await app.stop();
63
+ app.stop();
64
64
  }
65
65
  }
66
66
  });
@@ -80,20 +80,38 @@ export function setupExitHandlers(app) {
80
80
  }
81
81
  process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
82
82
  });
83
- process.on("SIGTERM", function () {
83
+ process.on("SIGTERM", async function () {
84
84
  app.logger?.info('SIGTERM received');
85
+ if (app.server) {
86
+ await Promise.race([
87
+ app.stop(),
88
+ new Promise(r => setTimeout(r, 5000))
89
+ ]);
90
+ }
85
91
  process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
86
92
  });
87
- process.on('SIGHUP', function () {
93
+ process.on('SIGHUP', async function () {
88
94
  app.logger?.info('SIGHUP received');
95
+ if (app.server) {
96
+ await Promise.race([
97
+ app.stop(),
98
+ new Promise(r => setTimeout(r, 5000))
99
+ ]);
100
+ }
89
101
  process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
90
102
  });
91
103
  /*process.on('SIGKILL', function () {
92
104
  server.logger.info('SIGKILL received');
93
105
  process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
94
106
  });*/
95
- process.on('SIGINT', function () {
107
+ process.on('SIGINT', async function () {
96
108
  app.logger?.info('SIGINT received');
109
+ if (app.server) {
110
+ await Promise.race([
111
+ app.stop(),
112
+ new Promise(r => setTimeout(r, 5000))
113
+ ]);
114
+ }
97
115
  process.exit(EXIT_CODES.ABNORMAL_UNCONTROLLED);
98
116
  });
99
117
  }
File without changes
@@ -28,6 +28,7 @@ export interface MiqroOptions extends ImportJSXFileOptions {
28
28
  https?: boolean;
29
29
  httpRedirect?: number;
30
30
  noMinify?: boolean;
31
+ allowedRedirectHosts?: string[];
31
32
  }
32
33
  export interface InflateOptions {
33
34
  inflateDir?: string;
@@ -383,7 +383,12 @@ export class Miqro {
383
383
  if (this.options?.httpRedirect) {
384
384
  this.httpsRedirectServer = new App();
385
385
  this.httpsRedirectServer.use(async (req, res) => {
386
- const hostname = req.headers.host.split(":").length > 1 ? req.headers.host.split(":")[0] : req.headers.host;
386
+ const hostname = req.headers.host?.split(":")[0] ?? "";
387
+ const allowed = this.options?.allowedRedirectHosts;
388
+ if (allowed && !allowed.includes(hostname)) {
389
+ res.writeHead(400).end("Invalid Host header");
390
+ return;
391
+ }
387
392
  return await res.redirect('https://' + hostname + ":" + this.options.port + req.url);
388
393
  });
389
394
  }