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

[ResponseOps] Hyperlinks in Slack messages are broken when there is "_" or "*" in the URL #170067

Merged
merged 5 commits into from
Oct 30, 2023

Conversation

doakalexi
Copy link
Contributor

@doakalexi doakalexi commented Oct 27, 2023

Resolves #165673

Summary

escapeSlack function in the mustasche_renderer breakes the hyperlinks by wrapping the URL with backticks.
So the below markdown template does not work.

<{{context.alertDetailsUrl}}|View alert details>

This PR removes the code that adds backticks.
With this change action variables with text wrapped in asterisks *text* will render as text or wrapped in underscores _text_ will render as text .

Checklist

To verify

  • Create a slack connector
  • Create a rule that uses a slack connector and use the above markdown template
  • Verify that hyperlink is working properly in slack

@doakalexi doakalexi changed the title Removing code to wrap links in ticks [ResponseOps] Hyperlinks in Slack messages are broken when there is "_" or "*" in the URL Oct 27, 2023
@doakalexi doakalexi added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) bug Fixes for quality problems that affect the customer experience release_note:fix v8.12.0 labels Oct 27, 2023
@doakalexi doakalexi marked this pull request as ready for review October 30, 2023 14:13
@doakalexi doakalexi requested a review from a team as a code owner October 30, 2023 14:13
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@@ -144,13 +144,6 @@ function escapeSlack(value: unknown): string {
if (value == null) return '';

const valueString = `${value}`;
// if the value contains * or _, escape the whole thing with back tics
Copy link
Member

Choose a reason for hiding this comment

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

This feels like it's too broad of a change. The reason we escape variable content containing * or _ is to prevent Slack from treating these as bold or italic. By removing this escaping completely, variables with those characters will end up causing probably unwanted style changes in the message.

I wonder if we can be a little more specific. Could we check if the value is a URL (see if URL.parse() or whatever doesn't throw an error)? If it IS a URL, do something different, otherwise do the existing thing (wrap the whole thing in back-tics).

As an additional thought, I wonder if we should uri encode the URL while we're at it? This would fix some additional issues, but is somewhat magical, so my brain says no ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in this commit 1c76b5f

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. Tested by setting server.publicBaseUrl: http://local_host:5601/, and then adding a Slack action that renders {{kibanaBaseUrl}} - no back tics!

@doakalexi doakalexi enabled auto-merge (squash) October 30, 2023 18:26
@doakalexi doakalexi merged commit 8fe512b into elastic:main Oct 30, 2023
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Cypress Tests #10 / Changing alert status Opening alerts can mark a closed alert as open can mark a closed alert as open

Metrics [docs]

✅ unchanged

History

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

@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting bug Fixes for quality problems that affect the customer experience release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hyperlinks in Slack messages are broken when there is "_" or "*" in the URL
5 participants