-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[AzureMonitorAutoConfigure] Validate ingestion and Live Metrics redirect targets #50117
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
Open
xiang17
wants to merge
9
commits into
main
Choose a base branch
from
xiang17/redirect-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+334
−11
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1d47b28
fix PoC A
xiang17 1e391c5
additional check on domain
xiang17 bbee728
add PR link in changelog
xiang17 b68d1df
Merge branch 'main' into xiang17/redirect-policy
xiang17 b7bfaba
Merge branch 'main' into xiang17/redirect-policy
xiang17 a083a81
Merge branch 'main' into xiang17/redirect-policy
xiang17 7a788b8
Use universal domain list
xiang17 0b3325d
validate ingestion as well
xiang17 4d42a7a
Add `.applicationinsights.microsoft.com` in the allowlist. Allow redi…
xiang17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...or/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseRedirectValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.monitor.opentelemetry.autoconfigure.implementation.quickpulse; | ||
|
|
||
| import com.azure.monitor.opentelemetry.autoconfigure.implementation.utils.RedirectPolicyHelper; | ||
|
|
||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
|
|
||
| final class QuickPulseRedirectValidator { | ||
|
|
||
| private QuickPulseRedirectValidator() { | ||
| } | ||
|
|
||
| static String validateAndGetEndpointPrefix(String configuredEndpoint, String redirectLink) | ||
| throws MalformedURLException { | ||
| URL configuredUrl = new URL(configuredEndpoint); | ||
| URL redirectUrl = new URL(redirectLink); | ||
|
|
||
| if (!RedirectPolicyHelper.isTrustedRedirect(configuredUrl, redirectUrl)) { | ||
| throw new MalformedURLException("Redirect host is outside the configured Live Metrics endpoint boundary"); | ||
| } | ||
|
|
||
| return redirectUrl.getProtocol() + "://" + redirectUrl.getAuthority() + "/"; | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
.../azure/monitor/opentelemetry/autoconfigure/implementation/utils/RedirectPolicyHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.monitor.opentelemetry.autoconfigure.implementation.utils; | ||
|
|
||
| import java.net.URL; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Trust boundary checks for server-issued redirects. Following an attacker-controlled redirect would cause the | ||
| * pipeline to attach a freshly signed credential (and the telemetry payload) to a foreign host. | ||
| */ | ||
| public final class RedirectPolicyHelper { | ||
|
|
||
| private static final String HTTPS = "https"; | ||
|
|
||
| private static final List<String> ALLOWED_REDIRECT_DOMAIN_SUFFIXES = Collections.unmodifiableList( | ||
| Arrays.asList(".livediagnostics.monitor.azure.com", ".monitor.azure.com", ".services.visualstudio.com", | ||
| ".applicationinsights.azure.com", ".applicationinsights.microsoft.com", ".monitor.azure.us", | ||
| ".applicationinsights.azure.us", ".monitor.azure.cn", ".applicationinsights.azure.cn")); | ||
|
|
||
| /** | ||
| * Returns whether a redirect target is safe to follow. | ||
| * <p> | ||
| * Stamp reassignment moves between suffixes (for example {@code rt.services.visualstudio.com} to | ||
| * {@code <region>.livediagnostics.monitor.azure.com}), so the target host is checked on its own rather than | ||
| * being required to share a suffix with the current host. | ||
| * | ||
| * @param currentUrl the endpoint the request is currently targeting | ||
| * @param redirectUrl the redirect target | ||
| * @return true if the redirect target is trusted | ||
| */ | ||
| public static boolean isTrustedRedirect(URL currentUrl, URL redirectUrl) { | ||
| if (!HTTPS.equalsIgnoreCase(redirectUrl.getProtocol()) | ||
| || redirectUrl.getUserInfo() != null | ||
| || !isDefaultPort(redirectUrl)) { | ||
| return false; | ||
| } | ||
|
|
||
| String redirectHost = canonicalHost(redirectUrl); | ||
| if (redirectHost.isEmpty()) { | ||
| return false; | ||
| } | ||
|
|
||
| // A redirect back to the current host stays inside the boundary the customer already chose, which keeps | ||
| // custom endpoints and reverse proxies working. | ||
| return redirectHost.equals(canonicalHost(currentUrl)) || hasAllowedSuffix(redirectHost); | ||
| } | ||
|
|
||
| private static boolean hasAllowedSuffix(String host) { | ||
| for (String suffix : ALLOWED_REDIRECT_DOMAIN_SUFFIXES) { | ||
| if (host.endsWith(suffix)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static boolean isDefaultPort(URL url) { | ||
| return url.getPort() == -1 || url.getPort() == url.getDefaultPort(); | ||
| } | ||
|
|
||
| private static String canonicalHost(URL url) { | ||
| String host = url.getHost(); | ||
| if (host == null) { | ||
| return ""; | ||
| } | ||
| String canonicalHost = host.toLowerCase(Locale.ROOT); | ||
| while (canonicalHost.endsWith(".")) { | ||
| canonicalHost = canonicalHost.substring(0, canonicalHost.length() - 1); | ||
| } | ||
| return canonicalHost; | ||
| } | ||
|
|
||
| private RedirectPolicyHelper() { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.