ecrs-auth-core 1.0.76 → 1.0.79
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 +20 -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,39 @@ 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)
|
|
142
|
+
console.log('Headers:', request.headers);
|
|
141
143
|
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
144
|
if (xForwardedFor) {
|
|
148
145
|
const ips = Array.isArray(xForwardedFor)
|
|
149
146
|
? xForwardedFor
|
|
150
147
|
: xForwardedFor.split(',');
|
|
151
|
-
|
|
148
|
+
ip = ips[0].trim();
|
|
152
149
|
}
|
|
153
150
|
// Check X-Real-IP header (nginx)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
else if (request.headers['x-real-ip']) {
|
|
152
|
+
const xRealIp = request.headers['x-real-ip'];
|
|
153
|
+
ip = Array.isArray(xRealIp) ? xRealIp[0] : xRealIp;
|
|
157
154
|
}
|
|
158
155
|
// Check CF-Connecting-IP (Cloudflare)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
else if (request.headers['cf-connecting-ip']) {
|
|
157
|
+
const cfIp = request.headers['cf-connecting-ip'];
|
|
158
|
+
ip = Array.isArray(cfIp) ? cfIp[0] : cfIp;
|
|
162
159
|
}
|
|
163
160
|
// Use Express native request.ip (handles proxies if trust proxy is set)
|
|
164
|
-
if (request.ip) {
|
|
165
|
-
|
|
161
|
+
else if (request.ip) {
|
|
162
|
+
ip = request.ip;
|
|
166
163
|
}
|
|
167
164
|
// Fallback to socket remote address
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
else if (request.socket.remoteAddress) {
|
|
166
|
+
ip = request.socket.remoteAddress;
|
|
167
|
+
}
|
|
168
|
+
// Clean IPv6-mapped IPv4 format (::ffff:192.168.0.166 -> 192.168.0.166)
|
|
169
|
+
if (ip.startsWith('::ffff:')) {
|
|
170
|
+
ip = ip.substring(7);
|
|
171
|
+
}
|
|
172
|
+
return ip || 'Unknown';
|
|
170
173
|
}
|
|
171
174
|
};
|
|
172
175
|
exports.AuthController = AuthController;
|