@@ -14,15 +14,18 @@ module.exports = class extends think.Logic {
14
14
15
15
async __before ( ) {
16
16
const referrer = this . ctx . referrer ( true ) ;
17
- let origin = this . ctx . request . header . origin ;
17
+ let origin = this . ctx . origin ;
18
+
18
19
if ( origin ) {
19
20
try {
20
21
const parsedOrigin = new URL ( origin ) ;
22
+
21
23
origin = parsedOrigin . hostname ;
22
- } catch ( error ) {
23
- console . error ( 'Invalid origin format:' , origin ) ;
24
+ } catch ( e ) {
25
+ console . error ( 'Invalid origin format:' , origin , e ) ;
24
26
}
25
27
}
28
+
26
29
let { secureDomains } = this . config ( ) ;
27
30
28
31
if ( secureDomains ) {
@@ -51,10 +54,16 @@ module.exports = class extends think.Logic {
51
54
try {
52
55
return new RegExp ( domain . slice ( 1 , - 1 ) ) ; // 去掉斜杠并创建 RegExp 对象
53
56
} catch ( e ) {
54
- console . error ( 'Invalid regex pattern in secureDomains:' , domain ) ;
57
+ console . error (
58
+ 'Invalid regex pattern in secureDomains:' ,
59
+ domain ,
60
+ e ,
61
+ ) ;
62
+
55
63
return null ;
56
64
}
57
65
}
66
+
58
67
return domain ;
59
68
} )
60
69
. filter ( Boolean ) ; // 过滤掉无效的正则表达式
@@ -64,7 +73,7 @@ module.exports = class extends think.Logic {
64
73
const isSafe = secureDomains . some ( ( domain ) =>
65
74
think . isFunction ( domain . test )
66
75
? domain . test ( checking )
67
- : domain === checking
76
+ : domain === checking ,
68
77
) ;
69
78
70
79
if ( ! isSafe ) {
@@ -111,7 +120,7 @@ module.exports = class extends think.Logic {
111
120
'2fa' ,
112
121
'label' ,
113
122
] ,
114
- }
123
+ } ,
115
124
) ;
116
125
117
126
if ( think . isEmpty ( user ) ) {
@@ -213,13 +222,13 @@ module.exports = class extends think.Logic {
213
222
} ;
214
223
215
224
const response = await fetch ( requestUrl , options ) . then ( ( resp ) =>
216
- resp . json ( )
225
+ resp . json ( ) ,
217
226
) ;
218
227
219
228
if ( ! response . success ) {
220
229
think . logger . debug (
221
230
'RecaptchaV3 or Turnstile Result:' ,
222
- JSON . stringify ( response , null , '\t' )
231
+ JSON . stringify ( response , null , '\t' ) ,
223
232
) ;
224
233
225
234
return this . ctx . throw ( 403 ) ;
0 commit comments