Skip to content

Commit 8646c41

Browse files
committed
endpoints-control: strip brackets of IPv6 addresses for check API.
cloudendpoints#66
1 parent 86e0cbd commit 8646c41

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

endpoints-control/src/main/java/com/google/api/control/ControlFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright 2016 Google Inc. All Rights Reserved.
3+
* Copyright 2023 Uwe Trottmann
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
56
* you may not use this file except in compliance with the License.
@@ -370,6 +371,10 @@ private CheckRequestInfo createCheckInfo(HttpServletRequest request, String uri,
370371
apiKey = findDefaultApiKeyParam(request);
371372
}
372373

374+
// The Service Control check API expects IPv6 addresses formatted without brackets ('[' and ']'), so strip them.
375+
String ipAddress = request.getRemoteAddr();
376+
String strippedIpAddress = ipAddress.replace("[", "").replace("]", "");
377+
373378
return new CheckRequestInfo(new OperationInfo()
374379
.setApiKey(apiKey)
375380
.setApiKeyValid(!Strings.isNullOrEmpty(apiKey))
@@ -378,7 +383,7 @@ private CheckRequestInfo createCheckInfo(HttpServletRequest request, String uri,
378383
.setOperationId(nextOperationId())
379384
.setOperationName(info.getSelector())
380385
.setServiceName(serviceName))
381-
.setClientIp(request.getRemoteAddr())
386+
.setClientIp(strippedIpAddress)
382387
.setAndroidPackageName(request.getHeader(X_ANDROID_PACKAGE))
383388
.setAndroidCertificateFingerprint(request.getHeader(X_ANDROID_CERT))
384389
.setIosBundleId(request.getHeader(X_IOS_BUNDLE_ID));

0 commit comments

Comments
 (0)