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

[Actions] Removed double parsing when passing action url for validation #87928

Merged
merged 6 commits into from
Jan 19, 2021

Conversation

ymao1
Copy link
Contributor

@ymao1 ymao1 commented Jan 11, 2021

Summary

When creating actions, webhook action URLs were being double parsed as URLs (parsed as URL, then toString, then parsed again as URL) while during validation. This updates validation to pass in the configured URL as is and allow the shared validation method to parse the URL and hostname.

Checklist

Delete any items that are not applicable to this PR.

@ymao1 ymao1 self-assigned this Jan 11, 2021
return false;
}

function isHostnameAllowedInUri(config: ActionsConfigType, uri: string): boolean {
return pipe(
tryCatch(() => new URL(uri)),
map((url) => url.hostname),
tryCatch(() => url.parse(uri)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} catch (err) {
return i18n.translate('xpack.actions.builtin.slack.slackConfigurationErrorNoHostname', {
defaultMessage: 'error configuring slack action: unable to parse host name from webhookUrl',
});
}

try {
configurationUtilities.ensureHostnameAllowed(url.hostname);
configurationUtilities.ensureUriAllowed(configuredUrl);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am calling ensureUriAllowed both here and in the teams connector to be consistent with how I updated the webhook action. Pagerduty, Jira, Resilient and Servicenow were already all using ensureUriAllowed

@ymao1 ymao1 added Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.12.0 v8.0.0 labels Jan 12, 2021
@ymao1 ymao1 marked this pull request as ready for review January 12, 2021 12:57
@ymao1 ymao1 requested a review from a team as a code owner January 12, 2021 12:57
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ymao1
Copy link
Contributor Author

ymao1 commented Jan 13, 2021

@elasticmachine merge upstream

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, made a nit comment about a potentially extraneous boolean check

Was there an issue associated with this? For some reason I'm thinking there was, something about the parse, re-gen, parse yielding a different URL because of escaping or something? I didn't see an issue referenced, maybe I missed it. If there was, we should add a test for that case.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@ymao1 ymao1 merged commit 60f8b24 into elastic:master Jan 19, 2021
ymao1 added a commit to ymao1/kibana that referenced this pull request Jan 19, 2021
…on (elastic#87928)

* Removed double parsing when passing action url for validation

* Fixing functional test

* PR fixes

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>
ymao1 added a commit to ymao1/kibana that referenced this pull request Jan 19, 2021
…on (elastic#87928)

* Removed double parsing when passing action url for validation

* Fixing functional test

* PR fixes

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>
ymao1 added a commit to ymao1/kibana that referenced this pull request Jan 19, 2021
…on (elastic#87928)

* Removed double parsing when passing action url for validation

* Fixing functional test

* PR fixes

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	x-pack/plugins/actions/server/builtin_action_types/slack.ts
#	x-pack/plugins/actions/server/builtin_action_types/teams.test.ts
#	x-pack/plugins/actions/server/builtin_action_types/teams.ts
ymao1 added a commit that referenced this pull request Jan 19, 2021
…on (#87928) (#88728)

* Removed double parsing when passing action url for validation

* Fixing functional test

* PR fixes

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
ymao1 added a commit that referenced this pull request Jan 19, 2021
…on (#87928) (#88729)

* Removed double parsing when passing action url for validation

* Fixing functional test

* PR fixes

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
ymao1 added a commit that referenced this pull request Jan 20, 2021
…alidation (#87928) (#88730)

* [Actions] Removed double parsing when passing action url for validation (#87928)

* Removed double parsing when passing action url for validation

* Fixing functional test

* PR fixes

* PR fixes

Co-authored-by: Kibana Machine <[email protected]>
# Conflicts:
#	x-pack/plugins/actions/server/builtin_action_types/slack.ts
#	x-pack/plugins/actions/server/builtin_action_types/teams.test.ts
#	x-pack/plugins/actions/server/builtin_action_types/teams.ts

* Fixing bad merge

* Fixing types check
@mikecote mikecote added release_note:fix and removed release_note:skip Skip the PR/issue when compiling release notes labels Feb 2, 2021
@ymao1 ymao1 deleted the actions/allowed-hosts branch February 4, 2021 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.10.3 v7.11.0 v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants