When dealing with submit forms, even if they are sent with AJAX, you must play by the Never trust user’s input rule.
Every data-attribute
can be changed, edited via Inspector. Your only trusted validation should be on the server side, as you did with:
if ( isset($_POST['author_id']) || is_numeric($_POST['author_id']) )
Personally, I would inverse the logic and first check all the attributes before starting any action.
check_ajax_referer( '*****', 'security' );
if ( ! isset($_POST['author_id']) && ! is_numeric($_POST['author_id']) ) {
// tell the villain that this tower is watched
wp_send_json_error( 'Wrong author ID!' );
}
// now is safe to cache
$author_id = $_POST['author_id'];
Stolen from Codex.
The parameters are passed through a URI encoding so I wouldn’t worry too much about data type or casting.
Related Posts:
- Nonces can be reused multiple times? Bug / Security issue?
- ajaxurl not defined on front end
- How to store username and password to API in wordpress option DB?
- Why does WordPress add 0 (zero) to an Ajax response?
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- Saving data-URI to media library
- How to properly validate data from $_GET or $_REQUEST using WordPress functions?
- How can I run AJAX on a button click event?
- Can someone explain what wp_session_tokens are, and what are they used for?
- WordPress and PHP Sessions – Security and Performance
- How-to implement admin Ajax inside an admin WP_List_Table?
- What is the difference between esc_html and wp_filter_nohtml_kses?
- What is nonce and how to use it with Ajax in WordPress? [duplicate]
- Empty POST data on server on AJAX request using Angular $http
- Using AJAX in FrontEnd with WordPress Plugin Boilerplate (wppb.io)
- Nonce in settings API with tabbed navigation
- Log in from one wordpress website to another wordpress website
- Build path for a custom portfolio plugin
- Using AJAX in a plugin to submit form – REALLY confused
- wp_localize_script $handle
- Escaping built-in WP function return strings
- What is the difference between strip_tags and wp_filter_nohtml_kses?
- WP Cron doesn’t save or in post body
- How to enable users to down-vote in this simple voting counter (that uses the post meta)?
- Adding callback function for wp_ajax_ has no effect
- get all products of one category
- Get returned variable from a function to add_shortcode function
- Plugin Settings not Saving on Ajax re-ordered table
- How to post form in ajax mode and handle it in wordpress
- Using Ajax call in jQuery doesn’t work in widget
- WordPress restrict plugin file direct access
- WP_LOCALIZE_SCRIPT doesn’t work
- Plugin development: is adding empty index.php files necessary?
- Timeout on Admin-Ajax?
- Confusion on WP Nonce usage in my Plugin
- Admin-ajax.php appending a status code to ajax response
- Comment `Reply` link doesn’t work if comments are loaded from ajax
- Ajax in WordPress – path issue
- Cannot search post by taxonomy
- Coding a plugin on WordPress; when should I sanitize? [duplicate]
- Correct way check nonce (security) using old Options API
- WordPress Ajax callback function from plugin – OOP
- Why do I need to check if wp_nonce_field() exists before using it
- WP AJAX is not working, always returns 0
- Ensure function has completed before allowing another Ajax call
- Is there any way to check for user login and send him to login?
- WordPress security issue to output data from user input from theme option form
- Frontend Ajax call not working using wp_ajax, wp_enqueue_script and wp_localize_script
- Fetching the value of forms in WordPress AJAX
- include wp-blog-header not working on MAMP
- Any problem in using native jquery ajax style instead of using admin-ajax.php?
- Slow WP_query due to nested wp_query. Need Suggestions
- Show special field when correct shipping is chosen
- .mo translation strings not loading in PHP scripts that handle AJAX calls
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- Verify if user is wordpress logged in from another app since wordpress 4.0
- Woocommerce checkout update totals with datepicker
- Including the necessary functions for a custom ajax registration form
- Secure Pages Best Practice
- How can I rewrite a URL to pass requests to a custom method via AJAX? (I can’t use admin-ajax.php)
- How to localize admin.php only once
- get post attachment using ajax
- Dashboard – get status and position of metaboxes and pass them to ajax method
- Securing/Escaping Output of file content – reading via fread() in PHP
- Create a new post using rest api and save featured image using an external image url
- how to search users by ajax live search
- wp.template() returns tags in Ajax response
- How to get Metabox custom field to show checked if value is updated using post meta query?
- Storing data in wordpress database from ajax call from different website
- Fatal error: Uncaught Error: Call to undefined function get_option()
- best way to make a WordPresss multisite that is secure but at the same time supporting my plugin development efforts
- Video Security just like facebook [closed]
- Create custom HTML/JS app inside page
- Use just a shortcode from another page
- template_redirect or admin-ajax.php?
- how to get context information inside my funcion
- Is disabling test_form in wp_handle_upload a security concern?
- How to connect my wordpress plugin to a remote database securely?
- wp_nonce_field displaying twice
- AJAX form post returns 0
- Is it necessary to do validation again when retrieving data from database?
- Update Data parameter of a wp_localize_script() call
- jquery & ajax sending data to php
- wp_localize_script is not adding a global variable for javascript
- Can’t get AJAX call working in custom plugin
- Checking a WordPress for OWASP top 10 vulnerabilities [closed]
- Bad Request in AJAX
- Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
- 400 Bad Request, in wordpress theme development, wp_ajax
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- Ajax is not working in a loop
- ajax recursive calls on wordpress returning answers outsite the function scope
- add_submenu_page hooked function must explicitly check user capabilities – why?
- Ajax submit result opens in admin-ajax.php
- insert query on a custom table using ajax with jQuery plugin Jeditable
- How to get error object returned by wp_create_user
- Plugin AJAX Save to Custom Table
- Why would you use esc_attr() on internal functions?
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- Data not insert and update through ajax and jQuery in admin page?