🔒 Fix potential XPath injection in _element_find_by_text#478
Open
Dor-bl wants to merge 2 commits into
Open
Conversation
The input string 'text' was directly concatenated into the XPath query using format(), which could allow a malicious user to manipulate the XPath structure. This is fixed by using the utility function escape_xpath_value() and updating the XPath templates to work with the escaped (and already quoted) values. PR Title: 🔒 [security fix potential XPath injection in _element_find_by_text] 🎯 What: Fixed potential XPath injection vulnerability in the `_element_find_by_text` method.⚠️ Risk: Malicious input could be used to manipulate XPath queries, potentially allowing unauthorized access to elements or data within the application. 🛡️ Solution: Applied `utils.escape_xpath_value()` to the `text` parameter before incorporating it into XPath strings. Refactored the XPath templates to remove hardcoded quotes. Added comprehensive unit tests in `tests/keywords/test_element_security.py` to verify the fix.
Contributor
|
Thanks for the PR @Dor-bl, nice fix! I verified all escape branches produce valid XPath and the injection payload no longer escapes the literal. Could you add a test case for text containing both quote types (e.g. |
Contributor
Author
|
Done! Added a test case with mixed quotes to exercise the branch as requested. |
chsinger
approved these changes
Jul 11, 2026
Contributor
Author
|
@chsinger |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The input string 'text' was directly concatenated into the XPath query using format(), which could allow a malicious user to manipulate the XPath structure. This is fixed by using the utility function escape_xpath_value() and updating the XPath templates to work with the escaped (and already quoted) values.
PR Title: 🔒 [security fix potential XPath injection in _element_find_by_text]
🎯 What: Fixed potential XPath injection vulnerability in the
⚠️ Risk: Malicious input could be used to manipulate XPath queries, potentially allowing unauthorized access to elements or data within the application.
_element_find_by_textmethod.🛡️ Solution: Applied
utils.escape_xpath_value()to thetextparameter before incorporating it into XPath strings. Refactored the XPath templates to remove hardcoded quotes. Added comprehensive unit tests intests/keywords/test_element_security.pyto verify the fix.Implements
Fixing