Prevent Command Injection in introduction/views.py - #23394
Open
pixee-integration-test[bot] wants to merge 1 commit into
Open
Prevent Command Injection in introduction/views.py#23394pixee-integration-test[bot] wants to merge 1 commit into
pixee-integration-test[bot] wants to merge 1 commit into
Conversation
|
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.



Pixee Scan: d6a5c69e-0dfc-4921-8f83-fb77f37df46d
Confidence: HIGH
Fix confidence is a rating derived from an internal benchmark and includes High, Medium, and Low confidence fixes. It comprises three weighted scores reflecting the safety, effectiveness and cleanliness of Pixee's code changes within a fix. View Details in Pixee.
Remediation
This change fixes finding AZVdjxO-h0BHfERFoIIK.
Details
Prevent Command Injection in introduction/views.py
Summary
Prevented command injection in
introduction/views.pyby removing shell-based command construction from the domain lookup path.Vulnerability Description
Command Injection occurs when an application builds an operating system command from untrusted input and executes it through a shell. This is dangerous because shell metacharacters and argument separators can let an attacker run arbitrary commands with the application's privileges. A successful exploit can expose data, modify files, or fully compromise the host process.
Changes Made
The vulnerable code in
introduction/views.pyconcatenated the user-controlleddomainvalue intonslookupordigcommand strings and executed them withsubprocess.Popen(..., shell=True). That pattern allowed the POSTed domain field to be interpreted as part of a shell command instead of as data. The fix added validation to reject empty or malformed domains, normalized the input with trimming, and required the value to match a strict hostname/IP regular expression before execution. It also switched to passing['nslookup', domain]or['dig', domain]as an argument list and setshell=False, which keeps the lookup utility behavior while separating code from user data.Guidance Adherence
Source: Pixee Knowledge Base
Applied the following guidance from the remediation guidance and Sonar issue description for pythonsecurity:S2076:
['nslookup', domain]/['dig', domain]) instead of a formatted string, andsubprocess.Popenis invoked withshell=False, which aligns with the recommended safe approach for command execution and removes the shell-injection vector.No specific preferred library/framework, style convention, or dependency addition was required by the guidance, so those criteria are satisfied by default. The remediation approach matches the security guidance, and no new manifest dependency is needed.