ecrs-auth-core 1.0.76 → 1.0.78
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/dist/auth.controller.d.ts +1 -1
- package/dist/auth.controller.js +19 -17
- package/package.json +1 -1
|
@@ -42,7 +42,7 @@ export declare class AuthController {
|
|
|
42
42
|
*/
|
|
43
43
|
private parseUserAgent;
|
|
44
44
|
/**
|
|
45
|
-
* Extract client IP from request
|
|
45
|
+
* Extract client IP from request and clean IPv6-mapped IPv4 format
|
|
46
46
|
* Priority:
|
|
47
47
|
* 1. X-Forwarded-For header (proxy)
|
|
48
48
|
* 2. X-Real-IP header (nginx)
|
package/dist/auth.controller.js
CHANGED
|
@@ -128,7 +128,7 @@ let AuthController = class AuthController {
|
|
|
128
128
|
return { browser, os, deviceType };
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
-
* Extract client IP from request
|
|
131
|
+
* Extract client IP from request and clean IPv6-mapped IPv4 format
|
|
132
132
|
* Priority:
|
|
133
133
|
* 1. X-Forwarded-For header (proxy)
|
|
134
134
|
* 2. X-Real-IP header (nginx)
|
|
@@ -137,36 +137,38 @@ let AuthController = class AuthController {
|
|
|
137
137
|
* 5. socket.remoteAddress (direct connection)
|
|
138
138
|
*/
|
|
139
139
|
getClientIp(request) {
|
|
140
|
+
let ip = '';
|
|
140
141
|
// Check X-Forwarded-For header (most common with proxies)
|
|
141
142
|
const xForwardedFor = request.headers['x-forwarded-for'];
|
|
142
|
-
console.log('X-Forwarded-For header:', xForwardedFor);
|
|
143
|
-
console.log('Request IP:', request.ip);
|
|
144
|
-
console.log('Socket Remote Address:', request.socket.remoteAddress);
|
|
145
|
-
console.log('X-Real-IP header:', request.headers['x-real-ip']);
|
|
146
|
-
console.log('CF-Connecting-IP header:', request.headers['cf-connecting-ip']);
|
|
147
143
|
if (xForwardedFor) {
|
|
148
144
|
const ips = Array.isArray(xForwardedFor)
|
|
149
145
|
? xForwardedFor
|
|
150
146
|
: xForwardedFor.split(',');
|
|
151
|
-
|
|
147
|
+
ip = ips[0].trim();
|
|
152
148
|
}
|
|
153
149
|
// Check X-Real-IP header (nginx)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
else if (request.headers['x-real-ip']) {
|
|
151
|
+
const xRealIp = request.headers['x-real-ip'];
|
|
152
|
+
ip = Array.isArray(xRealIp) ? xRealIp[0] : xRealIp;
|
|
157
153
|
}
|
|
158
154
|
// Check CF-Connecting-IP (Cloudflare)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
else if (request.headers['cf-connecting-ip']) {
|
|
156
|
+
const cfIp = request.headers['cf-connecting-ip'];
|
|
157
|
+
ip = Array.isArray(cfIp) ? cfIp[0] : cfIp;
|
|
162
158
|
}
|
|
163
159
|
// Use Express native request.ip (handles proxies if trust proxy is set)
|
|
164
|
-
if (request.ip) {
|
|
165
|
-
|
|
160
|
+
else if (request.ip) {
|
|
161
|
+
ip = request.ip;
|
|
166
162
|
}
|
|
167
163
|
// Fallback to socket remote address
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
else if (request.socket.remoteAddress) {
|
|
165
|
+
ip = request.socket.remoteAddress;
|
|
166
|
+
}
|
|
167
|
+
// Clean IPv6-mapped IPv4 format (::ffff:192.168.0.166 -> 192.168.0.166)
|
|
168
|
+
if (ip.startsWith('::ffff:')) {
|
|
169
|
+
ip = ip.substring(7);
|
|
170
|
+
}
|
|
171
|
+
return ip || 'Unknown';
|
|
170
172
|
}
|
|
171
173
|
};
|
|
172
174
|
exports.AuthController = AuthController;
|