0
0
Wordpressframework~20 mins

Plugin security (nonces, sanitization) in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Plugin Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of a nonce in WordPress plugin security?

In WordPress plugin development, nonces are often used. What is their main purpose?

ATo verify that a request comes from a legitimate source and prevent CSRF attacks
BTo encrypt user data before saving it to the database
CTo speed up plugin execution by caching results
DTo validate user input formats like email or phone numbers
Attempts:
2 left
💡 Hint

Think about how plugins protect actions triggered by users from outside attackers.

component_behavior
intermediate
1:30remaining
What happens if you omit nonce verification in a WordPress plugin form submission?

Consider a WordPress plugin form that processes user input but does not verify the nonce. What is the likely outcome?

AThe form will not submit because WordPress blocks it automatically
BThe plugin will throw a fatal PHP error on submission
CThe form submission is vulnerable to CSRF attacks allowing unauthorized actions
DThe plugin will sanitize inputs automatically without nonce
Attempts:
2 left
💡 Hint

Think about what nonce verification protects against and what happens if it is missing.

📝 Syntax
advanced
2:00remaining
Which code snippet correctly verifies a nonce in a WordPress plugin?

Choose the code snippet that properly checks a nonce named 'my_nonce' sent via POST before processing the form.

Wordpress
<?php
if (/* your code here */) {
    wp_die('Security check failed');
} else {
    // process form
}
?>
Aif ( ! isset($_POST['my_nonce']) || ! wp_verify_nonce($_POST['my_nonce'], 'my_action') )
Bif ( wp_verify_nonce($_POST['my_nonce'], 'my_action') )
Cif ( isset($_POST['my_nonce']) && wp_verify_nonce($_POST['my_nonce'], 'my_action') )
Dif ( ! wp_verify_nonce('my_nonce', $_POST['my_action']) )
Attempts:
2 left
💡 Hint

Remember to check if the nonce exists and that verification returns true.

🔧 Debug
advanced
2:00remaining
Why does this plugin code fail to sanitize user input properly?

Review this code snippet from a WordPress plugin:

<?php
$user_input = $_POST['user_data'];
$clean_input = sanitize_text_field($user_input);
update_option('my_option', $user_input);
?>

Why is the sanitization ineffective?

ABecause sanitize_text_field() does not sanitize POST data
BBecause the unsanitized $user_input is saved instead of $clean_input
CBecause update_option() automatically sanitizes data
DBecause $user_input is sanitized twice causing errors
Attempts:
2 left
💡 Hint

Check which variable is saved to the database.

state_output
expert
2:00remaining
What is the output of this WordPress plugin code snippet regarding nonce verification and sanitization?

Given the following code snippet, what will be the output if the nonce is invalid and the user input is <script>alert('x')</script>?

Wordpress
<?php
if ( ! isset($_POST['my_nonce']) || ! wp_verify_nonce($_POST['my_nonce'], 'my_action') ) {
    echo 'Nonce verification failed';
    exit;
}
$input = sanitize_text_field($_POST['user_input']);
echo 'User input: ' . $input;
?>
AFatal error: Undefined index: my_nonce
BUser input: alert('x')
CUser input: &lt;script&gt;alert('x')&lt;/script&gt;
DNonce verification failed
Attempts:
2 left
💡 Hint

Consider what happens when nonce verification fails.