Challenge: Preventing Code Injection
Swipe to start coding
Refactor a function that previously used eval() to perform mathematical operations based on a string input, so that it cannot be exploited for code injection. Use only a dictionary of explicitly allowed operations.
- Only allow the operations "add", "subtract", "multiply", and "divide".
- For each allowed operation, perform the corresponding arithmetic on
aandb. - If an operation is not allowed, return
None. - For division, if
bis zero, returnNone.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Can you explain this in simpler terms?
What are some examples related to this topic?
Where can I learn more about this?
Awesome!
Completion rate improved to 5.56
Challenge: Preventing Code Injection
Desliza para mostrar el menú
Swipe to start coding
Refactor a function that previously used eval() to perform mathematical operations based on a string input, so that it cannot be exploited for code injection. Use only a dictionary of explicitly allowed operations.
- Only allow the operations "add", "subtract", "multiply", and "divide".
- For each allowed operation, perform the corresponding arithmetic on
aandb. - If an operation is not allowed, return
None. - For division, if
bis zero, returnNone.
Solución
¡Gracias por tus comentarios!
single