I have python code that parses input parameters:
parser=OptionParser()
parser.add_option("-o", dest="out", default=os.getenv('Path',None), help="file path")
parser.add_option("-c", dest="content", default=os.path.abspath(sys.path[0]), help="cont path")
parser.add_option("-t", dest="tool", default=os.getenv('Tool',None), help="tool path")
parser.add_option("-m", dest="man", default=os.getenv('Path',os.getcwd())+os.sep+"man.ini", help="man.ini location")
(opt, agrs)=parser.parse_args()
Checkmarx says the following: The application's main method calls an OS (shell) command with cmd, using an untrusted string with the command to execute.This could allow an attacker to inject an arbitrary command, and enable a Command Injection attack.The attacker may be able to inject the executed command via user input, parse_args... I think I need to strip the unneeded characters like |, & and ; but am unsure how/where to do it. Can I do it before this line "(opt, agrs)=parser.parse_args()"? Thanks