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

bookChallenge: Preventing Code Injection

Taak

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.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 5
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

Where can I learn more about this?

close

Awesome!

Completion rate improved to 5.56

bookChallenge: Preventing Code Injection

Veeg om het menu te tonen

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 5
single

single

some-alt