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

bookChallenge: Preventing Code Injection

Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 5
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

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

Scorri per mostrare il menu

Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 5
single

single

some-alt