-
Notifications
You must be signed in to change notification settings - Fork 0
CXH-2349: harden account hostname resolution #59
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,13 +50,26 @@ type Client struct { | |
| isWSAPIAvailable bool | ||
| } | ||
|
|
||
| // hostMatches reports whether hostname equals suffix or sits under it at a DNS | ||
| // label boundary. Plain strings.HasSuffix would let evilazuredatabricks.net | ||
| // match azuredatabricks.net; requiring the leading dot prevents that. | ||
| func hostMatches(hostname, suffix string) bool { | ||
| return hostname == suffix || strings.HasSuffix(hostname, "."+suffix) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi / out of scope: this is still case-sensitive —
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi / out of scope: trailing FQDN dot ( |
||
| } | ||
|
|
||
| func GetAccountHostname(hostname string) string { | ||
| if strings.HasSuffix(hostname, azureHost) { | ||
| hostname = strings.ToLower(strings.TrimSuffix(hostname, ".")) | ||
| switch { | ||
| case hostMatches(hostname, azureHost): | ||
| return "accounts." + azureHost | ||
| } else if strings.HasSuffix(hostname, gcpHost) { | ||
| case hostMatches(hostname, gcpHost): | ||
| return "accounts." + gcpHost | ||
| case hostMatches(hostname, defaultHost): | ||
| return "accounts." + defaultHost | ||
| default: | ||
| // Unknown hosts have no canonical account suffix, so prefix as given. | ||
| return "accounts." + hostname | ||
|
Comment on lines
+69
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: The comment is inaccurate for AWS — AWS does have a canonical account host ( |
||
| } | ||
| return "accounts." + hostname | ||
| } | ||
|
|
||
| func NewClient(ctx context.Context, httpClient *http.Client, hostname, accountHostname, accountID, baseURL string, auth Auth, excludeWorkspaces []string) (*Client, error) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion:
hostMatchesis case-sensitive, but DNS hostnames are not — a config value likeMyOrg.AzureDatabricks.net(or a trailing-dot FQDN) falls through to the default branch and yieldsaccounts.MyOrg.AzureDatabricks.netinstead of the canonical Azure account host. The failure is fail-safe rather than a spoofing bypass, but since this function's job is host classification it's worth normalising first, e.g.hostname = strings.ToLower(strings.TrimSuffix(hostname, "."))inGetAccountHostnamebefore matching.