Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Preventing Code Injection | Understanding Python Vulnerabilities
Python Security Best Practices

bookChallenge: Preventing Code Injection

Tarefa

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 a and b.
  • If an operation is not allowed, return None.
  • For division, if b is zero, return None.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 5
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

close

Awesome!

Completion rate improved to 5.56

bookChallenge: Preventing Code Injection

Deslize para mostrar o menu

Tarefa

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 a and b.
  • If an operation is not allowed, return None.
  • For division, if b is zero, return None.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 5
single

single

some-alt