diff --git a/lib/https/index.js b/lib/https/index.js index 342cc8b71..1f7465dac 100644 --- a/lib/https/index.js +++ b/lib/https/index.js @@ -21,7 +21,7 @@ function handleWebsocket(socket, clientIp, callback) { var filter = rules.resolveFilter(fullUrl); var now = Date.now(); var reqData = { - ip: clientIp || socket.remoteAddress, + ip: util.removeIPV6Prefix(clientIp || socket.remoteAddress), method: util.toUpperCase(socket.method) || 'GET', httpVersion: socket.httpVersion || '1.1', headers: headers diff --git a/lib/util/index.js b/lib/util/index.js index 3359eda7b..8a3c54f75 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -882,11 +882,21 @@ function getClientIp(req, forwarded) { || req.socket.remoteAddress; } catch(e) {} - return ip; + return removeIPV6Prefix(ip); } exports.getClientIp = getClientIp; +function removeIPV6Prefix(ip) { + if (typeof ip != 'string') { + return ip; + } + + return ip.indexOf('::ffff:') === 0 ? ip.substring(7) : ip; +} + +exports.removeIPV6Prefix = removeIPV6Prefix; + function getAuths(_url) { var auths = []; var options = typeof _url == 'string' ? url.parse(_url) : _url;