File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 3
3
*/
4
4
5
5
export const IPTools = new class {
6
+ privateRelayIPs : { minIP : number ; maxIP : number } [ ] = [ ] ;
6
7
// eslint-disable-next-line max-len
7
8
readonly ipRegex = / ^ ( 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 1 - 9 ] ? [ 0 - 9 ] ) \. ( 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 1 - 9 ] ? [ 0 - 9 ] ) \. ( 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 1 - 9 ] ? [ 0 - 9 ] ) \. ( 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 1 - 9 ] ? [ 0 - 9 ] ) $ / ;
8
9
getCidrRange ( cidr : string ) : { minIP : number ; maxIP : number } | null {
@@ -51,6 +52,24 @@ export const IPTools = new class {
51
52
if ( ! range ) return false ;
52
53
return range . minIP <= ip && ip <= range . maxIP ;
53
54
}
55
+
56
+ async loadPrivateRelayIPs ( ) {
57
+ const seen = new Set < string > ( ) ;
58
+ try {
59
+ const res = await ( await fetch ( "https://mask-api.icloud.com/egress-ip-ranges.csv" ) ) . text ( ) ;
60
+ for ( const line of res . split ( '\n' ) ) {
61
+ const [ range ] = line . split ( ',' ) ;
62
+ const [ ip ] = range . split ( '/' ) ;
63
+ if ( this . ipRegex . test ( ip ) && ! seen . has ( range ) ) {
64
+ const cidr = this . getCidrRange ( range ) ;
65
+ if ( cidr ) {
66
+ this . privateRelayIPs . push ( cidr ) ;
67
+ seen . add ( range ) ;
68
+ }
69
+ }
70
+ }
71
+ } catch { }
72
+ }
54
73
} ;
55
74
56
75
export default IPTools ;
Original file line number Diff line number Diff line change @@ -211,7 +211,12 @@ export class ActionContext {
211
211
}
212
212
isTrustedProxy ( ip : string ) {
213
213
// account for shit like ::ffff:127.0.0.1
214
- return ip === '::ffff:127.0.0.1' || Config . trustedproxies . some ( f => IPTools . checkPattern ( f , ip ) ) ;
214
+ const num = IPTools . ipToNumber ( ip ) || 0 ;
215
+ return (
216
+ ip === '::ffff:127.0.0.1' ||
217
+ Config . trustedproxies . some ( f => IPTools . checkPattern ( f , ip ) ) ||
218
+ IPTools . privateRelayIPs . some ( f => f . minIP <= num && num <= f . maxIP )
219
+ ) ;
215
220
}
216
221
_ip = '' ;
217
222
getIp ( ) {
@@ -415,3 +420,5 @@ export class Server {
415
420
) ;
416
421
}
417
422
}
423
+
424
+ void IPTools . loadPrivateRelayIPs ( ) ;
You can’t perform that action at this time.
0 commit comments