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?
- 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
- What is the difference between esc_html and wp_filter_nohtml_kses?
- Empty POST data on server on AJAX request using Angular $http
- Nonce in settings API with tabbed navigation
- Log in from one wordpress website to another wordpress website
- wp_localize_script $handle
- Escaping built-in WP function return strings
- 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)?
- 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
- Timeout on Admin-Ajax?
- Confusion on WP Nonce usage in my Plugin
- Comment `Reply` link doesn’t work if comments are loaded from ajax
- Ajax in WordPress – path issue
- Correct way check nonce (security) using old Options API
- 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
- include wp-blog-header not working on MAMP
- Slow WP_query due to nested wp_query. Need Suggestions
- .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?
- Woocommerce checkout update totals with datepicker
- Including the necessary functions for a custom ajax registration form
- Secure Pages Best Practice
- 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
- how to search users by ajax live search
- 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
- 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
- Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
- 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
- add_submenu_page hooked function must explicitly check user capabilities – why?
- How to get error object returned by wp_create_user
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- Setting a JSON web token from a secondary api as a secure cookie on WordPress
- How do I get rid of my inclusion race-condition on wp_enqueue_script
- Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
- ajax working when function is on child theme but not in plugin page
- AJAX call to admin-ajax.php by subscriber returns home page
- Ajax function is not working on WordPress
- About a programming language starts with [closed]
- Workflow for new importer plugin – your advices?
- How can I save a password securely as a settings field
- AJAX request not routing through proxy
- Ajax on the Administration Side of plugin – returns 0
- How to do admin ajax request in a plugin for rest api
- Ajax action has 200 status but response of No response data available for this request
- WordPress Does not grab the string sends useing AJAX response, wp_ajax hook
- GET request return value as error instead of success
- Bad request 400 using class based files
- Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin
- ajax stopped working when not logged in wordpress
- ajax response strips multidimensional array and unable to decode
- 400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true
- Rate limiting ajax requests in WordPress
- ajax-action.php can’t find added action
- How do I make secure API calls from my WordPress plugin?
- esc_attr() on hard coded string
- Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework
- AJAX call of function containing javascript which is not loaded (Plugin development)
- $_SESSION inside php function executed by AJAX
- Two same AJAX calls – one is working, other doesn’t
- How to include files in the loop via ajax
- How to handle ajax Request in a complex-structured plugin?
- Filterable posts using categories
- How to get values from Tinymce visual editor popup?
- PHP includes with AJAX actions
- WordPress function is not called and ajax return 0
- Experts opinions needed: How (in)secure is this approach?
- Ajax call not working with
- WP Ajax on page load not working on bluehost but was working on Godaddy
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- Can’t get query string in ajax call
- Data Validation, dynamically generated fields (select for example)
- An adiitional function fires on my AJAX submit
- Fatal error: Call to a member function query() on a non-object in my ajaxpage
- Page reload occurs before request finishes
- Trigger a JavaScript function based on the data fetched from Woo commerce hook
- Return custom product in ajax call loop