Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Java 11 IPv6 format crash #1

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
* Copyright 2023 Uwe Trottmann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -370,6 +371,10 @@ private CheckRequestInfo createCheckInfo(HttpServletRequest request, String uri,
apiKey = findDefaultApiKeyParam(request);
}

// The Service Control check API expects IPv6 addresses formatted without brackets ('[' and ']'), so strip them.
String ipAddress = request.getRemoteAddr();
String strippedIpAddress = ipAddress.replace("[", "").replace("]", "");

return new CheckRequestInfo(new OperationInfo()
.setApiKey(apiKey)
.setApiKeyValid(!Strings.isNullOrEmpty(apiKey))
Expand All @@ -378,7 +383,7 @@ private CheckRequestInfo createCheckInfo(HttpServletRequest request, String uri,
.setOperationId(nextOperationId())
.setOperationName(info.getSelector())
.setServiceName(serviceName))
.setClientIp(request.getRemoteAddr())
.setClientIp(strippedIpAddress)
.setAndroidPackageName(request.getHeader(X_ANDROID_PACKAGE))
.setAndroidCertificateFingerprint(request.getHeader(X_ANDROID_CERT))
.setIosBundleId(request.getHeader(X_IOS_BUNDLE_ID));
Expand Down