Python: Fortify: How to fix Dynamic Code Evaluation: Code Injection

Viewed 15

Below code is getting caught in scanning

format = "%Y-%m-%dT%H:%M:%S"
timenow = strftime(format, gmtime())
if endtime == "":
    datestring = input("Enter Time in format YYYY-MM-DDTHH:MM:SS").strip()
else:
    datestring = input("Enter starttime in format YYYY-MM-DDTHH:MM:SS").strip()
try:
    datetime.strptime(datestring, format)
    timediff = self.time_difference(timenow, datestring)

except ValueError:
    print("This is the incorrect date string format.")

Line caring datestring = is giving issue.

code issue detail:
Issue category: Dynamic Code Evaluation: Code Injection

Any help how can i fix this. As I need to take input from user, cant change it to menu item.

0 Answers
Related