-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 code scanning alert no. 494: Incomplete string escaping or encoding #204528
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Tested locally, it works as expected. And it passes the helper tests. |
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
cc @fkanout |
@@ -18,7 +18,7 @@ export const getLensOperationFromRuleMetric = (metric: GenericMetric): LensOpera | |||
const { aggType, field, filter = '' } = metric; | |||
let operation: string = aggType; | |||
const operationArgs: string[] = []; | |||
const escapedFilter = filter.replace(/'/g, "\\'"); | |||
const escapedFilter = filter.replace(/\\/g, '\\\\').replace(/'/g, "\\'"); |
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.
Can we add a test for this helper that fails before this fix?
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.
@maryam-saeidi I have already added a test for this helper in another PR. This PR is security-related only.
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.
Oh, really? Thanks for sharing. How does it work if we add a test before having the actual fix? I am not familiar with how the security scanning works.
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/12377521690 |
…ng (elastic#204528) Fixes [https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494) Fixes elastic#1311 Escape first backslash occurrences and all single quotes in the `filter` string. (cherry picked from commit cc34e97)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…encoding (#204528) (#204616) # Backport This will backport the following commits from `main` to `8.x`: - [Fix code scanning alert no. 494: Incomplete string escaping or encoding (#204528)](#204528) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Faisal Kanout","email":"faisal.kanout@elastic.co"},"sourceCommit":{"committedDate":"2024-12-17T16:45:16Z","message":"Fix code scanning alert no. 494: Incomplete string escaping or encoding (#204528)\n\nFixes\r\n[https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494)\r\nFixes #1311\r\n\r\nEscape first backslash occurrences and all single quotes in the `filter`\r\nstring.","sha":"cc34e97de4d2d8a5509eec5e4f9ffcb7338ed54a","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","Team:obs-ux-management"],"title":"Fix code scanning alert no. 494: Incomplete string escaping or encoding","number":204528,"url":"https://github.com/elastic/kibana/pull/204528","mergeCommit":{"message":"Fix code scanning alert no. 494: Incomplete string escaping or encoding (#204528)\n\nFixes\r\n[https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494)\r\nFixes #1311\r\n\r\nEscape first backslash occurrences and all single quotes in the `filter`\r\nstring.","sha":"cc34e97de4d2d8a5509eec5e4f9ffcb7338ed54a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204528","number":204528,"mergeCommit":{"message":"Fix code scanning alert no. 494: Incomplete string escaping or encoding (#204528)\n\nFixes\r\n[https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494)\r\nFixes #1311\r\n\r\nEscape first backslash occurrences and all single quotes in the `filter`\r\nstring.","sha":"cc34e97de4d2d8a5509eec5e4f9ffcb7338ed54a"}}]}] BACKPORT--> Co-authored-by: Faisal Kanout <faisal.kanout@elastic.co>
…ng (elastic#204528) Fixes [https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494) Fixes elastic#1311 Escape first backslash occurrences and all single quotes in the `filter` string.
…ng (elastic#204528) Fixes [https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494) Fixes elastic#1311 Escape first backslash occurrences and all single quotes in the `filter` string.
…ng (elastic#204528) Fixes [https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494) Fixes elastic#1311 Escape first backslash occurrences and all single quotes in the `filter` string.
…ng (elastic#204528) Fixes [https://github.com/elastic/kibana/security/code-scanning/494](https://github.com/elastic/kibana/security/code-scanning/494) Fixes elastic#1311 Escape first backslash occurrences and all single quotes in the `filter` string.
Fixes https://github.com/elastic/kibana/security/code-scanning/494
Fixes #1311
Escape first backslash occurrences and all single quotes in the
filter
string.