Challenge - 5 Problems
Nonce Verification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a WordPress nonce verification fails?
Consider a WordPress plugin that uses
check_admin_referer('my_action') to verify a nonce. What is the typical behavior if the nonce is invalid or missing?Attempts:
2 left
💡 Hint
Think about how WordPress protects admin actions from unauthorized access.
✗ Incorrect
The check_admin_referer() function verifies the nonce and if it fails, it triggers a WordPress error and stops the script execution to prevent unauthorized actions.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly verifies a nonce in a WordPress AJAX handler?
You want to verify a nonce sent via POST in your AJAX handler function. Which snippet correctly checks the nonce named 'my_nonce'?
Attempts:
2 left
💡 Hint
Remember the order of parameters for
wp_verify_nonce and how to handle failure.✗ Incorrect
wp_verify_nonce() takes the nonce value first, then the action string. It returns false if invalid, so the condition negates it to trigger wp_die().
❓ state_output
advanced2:00remaining
What is the output of this nonce verification code snippet?
Given the following code in a WordPress plugin, what will be the output if the nonce is valid?
Wordpress
<?php if (isset($_POST['my_nonce']) && wp_verify_nonce($_POST['my_nonce'], 'save_data')) { echo 'Nonce verified'; } else { echo 'Nonce failed'; } ?>
Attempts:
2 left
💡 Hint
Check the condition and what happens when the nonce is valid.
✗ Incorrect
If the nonce is set and valid, the code echoes 'Nonce verified'. Otherwise, it echoes 'Nonce failed'.
🔧 Debug
advanced2:00remaining
Why does this nonce verification always fail?
Identify the reason why the nonce verification fails every time in this code snippet:
Wordpress
<?php if (!wp_verify_nonce('save_data', $_POST['my_nonce'])) { wp_die('Invalid nonce'); } ?>
Attempts:
2 left
💡 Hint
Check the order of parameters for wp_verify_nonce.
✗ Incorrect
The first parameter to wp_verify_nonce() must be the nonce value, and the second is the action string. Reversing them causes verification to fail.
🧠 Conceptual
expert2:00remaining
Why is nonce verification important in WordPress forms?
Choose the best explanation for why WordPress uses nonce verification in forms and AJAX requests.
Attempts:
2 left
💡 Hint
Think about what kind of attacks nonce verification protects against.
✗ Incorrect
Nonces in WordPress protect against CSRF attacks by verifying that requests come from legitimate users and not attackers.