-
Notifications
You must be signed in to change notification settings - Fork 223
Potential fix for code scanning alert no. 10: XPath injection #35
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| using System.Web.UI.WebControls; | ||
| using System.Xml; | ||
| using System.Xml.XPath; | ||
| using System.Text.RegularExpressions; | ||
|
|
||
| namespace OWASP.WebGoat.NET | ||
| { | ||
|
|
@@ -23,9 +24,15 @@ protected void Page_Load(object sender, EventArgs e) | |
|
|
||
| private void FindSalesPerson(string state) | ||
| { | ||
| // Accept only alphabetic 2-letter abbreviations for state (e.g., "ny", "ca") | ||
| if (string.IsNullOrEmpty(state) || !System.Text.RegularExpressions.Regex.IsMatch(state, "^[a-zA-Z]{2}$")) | ||
| { | ||
| // Invalid state input, do not proceed or handle accordingly | ||
| return; | ||
|
Comment on lines
+27
to
+31
|
||
| } | ||
| XmlDocument xDoc = new XmlDocument(); | ||
| xDoc.LoadXml(xml); | ||
| XmlNodeList list = xDoc.SelectNodes("//salesperson[state='" + state + "']"); | ||
| XmlNodeList list = xDoc.SelectNodes("//salesperson[state='" + state.ToLower() + "']"); | ||
|
||
| if (list.Count > 0) | ||
| { | ||
|
|
||
|
|
||
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.
The fully qualified namespace is unnecessary here since RegularExpressions is already imported at line 9. Use Regex.IsMatch directly instead of System.Text.RegularExpressions.Regex.IsMatch for better code readability and consistency with the import statement.