Skip to content

Commit

Permalink
fix(server): fix lint in logic/base
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Jan 29, 2025
1 parent 238fc32 commit 4c514be
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/server/src/logic/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ module.exports = class extends think.Logic {

async __before() {
const referrer = this.ctx.referrer(true);
let origin = this.ctx.request.header.origin;
let origin = this.ctx.origin;

if (origin) {
try {
const parsedOrigin = new URL(origin);

origin = parsedOrigin.hostname;
} catch (error) {
console.error('Invalid origin format:', origin);
} catch (e) {
console.error('Invalid origin format:', origin, e);
}
}

let { secureDomains } = this.config();

if (secureDomains) {
Expand Down Expand Up @@ -51,10 +54,16 @@ module.exports = class extends think.Logic {
try {
return new RegExp(domain.slice(1, -1)); // 去掉斜杠并创建 RegExp 对象
} catch (e) {
console.error('Invalid regex pattern in secureDomains:', domain);
console.error(
'Invalid regex pattern in secureDomains:',
domain,
e,
);

return null;
}
}

return domain;
})
.filter(Boolean); // 过滤掉无效的正则表达式
Expand All @@ -64,7 +73,7 @@ module.exports = class extends think.Logic {
const isSafe = secureDomains.some((domain) =>
think.isFunction(domain.test)
? domain.test(checking)
: domain === checking
: domain === checking,
);

if (!isSafe) {
Expand Down Expand Up @@ -111,7 +120,7 @@ module.exports = class extends think.Logic {
'2fa',
'label',
],
}
},
);

if (think.isEmpty(user)) {
Expand Down Expand Up @@ -213,13 +222,13 @@ module.exports = class extends think.Logic {
};

const response = await fetch(requestUrl, options).then((resp) =>
resp.json()
resp.json(),
);

if (!response.success) {
think.logger.debug(
'RecaptchaV3 or Turnstile Result:',
JSON.stringify(response, null, '\t')
JSON.stringify(response, null, '\t'),
);

return this.ctx.throw(403);
Expand Down

0 comments on commit 4c514be

Please sign in to comment.