Admin Ajax Security

Though its name may sound technical, admin-ajax.php is crucial in making websites more interactive and responsive. It brings the magic of Ajax to the WordPress admin area and frontend, enabling dynamic updates without reloading the entire page.

Let’s explore the functionality of admin-ajax.php and its security importance.

What is admin-ajax.php in WordPress?

Admin-ajax.php is like a superhero in the WordPress universe.

It handles special requests from WordPress plugins, themes, and custom scripts. Think of it as a central hub that receives and processes instructions from various parts of a website, allowing specific actions to be performed without disrupting the user experience.

The Power of Ajax

Ajax, which stands for Asynchronous JavaScript and XML, is the magic behind admin-ajax.php. It enables websites to update specific page parts without requiring a full page reload.

Imagine having a toy car that you can modify by changing individual parts without dismantling the entire car. Ajax works similarly, making websites faster, smoother, and more interactive.

Dynamic Updates Made Easy

Admin-ajax.php empowers plugins and themes to perform tasks seamlessly. For example, you want to submit a form on a WordPress site. With admin-ajax.php, the form can be submitted in the background without interrupting your browsing.

This allows the website to update only the necessary parts, such as displaying a success message or refreshing a specific section, instead of reloading the entire page.

Why is it essential to secure the “admin-ajax.php” path?

The default URL for the admin-ajax.php file is /wp-admin/admin-ajax.php. This URL is also used by hackers to upload viruses and scripts to websites.

This is because the admin-ajax.php file is a powerful file that can perform various actions on a website, including uploading files, changing settings, and executing commands.

There are a number of security risks associated with the admin-ajax.php file:

  • Cross-site scripting (XSS) attacks: An attacker can inject malicious JavaScript code into an AJAX request. This code could then be executed in the victim’s browser, allowing the attacker to steal cookies or other sensitive information.
  • Remote code execution (RCE): An attacker can exploit a vulnerability in the admin-ajax.php file to run arbitrary code on the victim’s server. This could allow the attacker to take complete control of the website.
  • File upload vulnerabilities: Some AJAX requests can upload files to a website. If an attacker can exploit a file upload vulnerability in the admin-ajax.php file, they could upload malicious files to the website.

While admin-ajax.php is a powerful tool, it’s important to address security concerns. Like any superhero, it must be vigilant against potential threats.

One common issue is unauthorized access to admin-ajax.php, which could lead to malicious actions on a website.

WordPress websites often use the default URL /wp-admin/admin-ajax.php to make AJAX calls on the front end.

Unfortunately, hackers can exploit this URL to upload malicious viruses and scripts to your website. To enhance your website’s security, it is crucial to change the admin-ajax.php path.

How to Secure Admin Ajax with WP Ghost

Activate Safe Mode or Ghost Mode

Begin by activating Safe Mode or Ghost Mode to open the path customization process.

  1. Access your WordPress dashboard after installing and activating the WP Ghost plugin.
  2. Go to WP Ghost > Change Paths > Level of Security.
  3. Select Safe Mode or Ghost Mode. Safe Mode provides basic protection, while Ghost Mode offers more advanced security features.
Activate Safe Mode or Ghost Mode

Change admin-ajax.php Path

With Safe Mode or Ghost Mode enabled, proceed to change the admin-ajax.php path.

  1. Go to WP Ghost > Change Paths > Ajax Security.
  2. Next to the Custom admin-ajax Path, you’ll see the predefined custom name for the admin-ajax path.
  3. Enter a different name for the admin-ajax path or keep the predefined custom name.
  4. Click the Save button to apply the changes.
Change admin-ajax.php Path

Hide wp-admin from Ajax URL

  1. Go to WP Ghost > Change Paths > Ajax Security.
  2. Switch on Hide wp-admin from Ajax URL to hide the wp-admin or custom admin path from ajax URL.
  3. Click the Save button to apply the changes.
Hide wp-admin from Ajax URL

Note! Hiding the wp-admin from Ajax calls is possible only when the admin-ajax.php path is changed.

Change Paths in Ajax Calls

When your WordPress site makes Ajax calls, it often requests data or content from the server, such as images or files.

By default, WordPress uses specific paths to locate these resources, which can reveal information about your site’s structure and plugins being used.

To enhance security and privacy, you may want to customize these paths.

  1. Go to WP Ghost > Change Paths > Ajax Security.
  2. Switch on Change Paths in Ajax Calls to change all paths within Ajax response.
  3. Click the Save button to apply the changes.
Change Paths in Ajax Calls

This feature’s unique aspect is that it modifies the paths in the Ajax requests and the responses received from the server. When the server sends back images or files as part of an Ajax response, WP Ghost intercepts this response and ensures that the paths to these resources are replaced with your custom paths.

This helps maintain security, privacy, and obfuscation of your site’s structure, enhancing its overall protection.

Running a Security Check

To ensure that the modified admin-ajax.php path is effectively hidden, it is recommended that you run a security check using the WP Ghost plugin. This will verify whether the changes made are functioning correctly.

Running a Security Check

Follow these steps to perform a security check:

  1. Go to WP Ghost > Security Check.
  2. Click the Run Full Security Check button to initiate a new security scan.
  3. The plugin will verify that the admin-ajax.php path has been successfully changed.
  4. If the admin-ajax.php path is hidden as intended, the security task will be marked as complete.

Note: If any issues or warnings are detected during the security check, review the plugin’s documentation or seek support for further assistance in resolving the identified issues.

Conclusion

By changing the admin-ajax.php path using the WP Ghost plugin, you can significantly enhance the security of your WordPress website. Remember to activate Safe Mode or Ghost Mode, customize the admin-ajax.php path, hide the wp-admin path from AJAX calls, and perform a security check to ensure your modified paths remain hidden.

Prioritizing security measures like these helps protect your website from potential hacking attempts and keeps your valuable data safe.

Troubleshooting

Theme Compatibility Check

After changing the admin-ajax.php path, it is important to ensure that your theme is compatible and working properly with the custom AJAX path. Follow these steps to perform a theme compatibility check:

  1. Use a different browser of open the website in private mode.
  2. Visit different pages of your website that use AJAX functionality.
  3. Verify that pages, products, forms using AJAX are functioning correctly.

Note! If you encounter any issues, it is possible that your theme may not be fully compatible with the custom AJAX path.

While changing or hiding the admin-ajax.php path using the WP Ghost plugin can enhance the security of your WordPress website, it may cause compatibility issues with specific themes, plugins, or functionalities.

If you encounter any problems after implementing these changes, delete the custom path and switch the Ajax path to default.

Theme Compatibility Check

Website Forms Are Not Submitting Correctly After Changing Ajax Path

If forms like contact or comments that are using Ajax to submit the values are not working correctly, follow these steps:

Clear all cache

If you have a cache plugin or use server caching, clear all the cache, as the change of paths has significantly changed the website’s structure.

Run a Frontend Test

Go to WP Ghost > Change Paths, click the Frontend Test button (on the sidebar) and follow the server configuration instructions, if any.

Frontend test fail
Permalink settings

Go to your WordPress dashboard, navigate to Settings > Permalinks, and click Save Changes to refresh the permalinks. This action can sometimes help resolve issues related to URL structures.

Save settings permalink
Plugin compatibility

Deactivate the other plugins and check if the website works correctly. If it works, activate the other plugins one by one to identify the one that is not working correctly with the custom admin-ajax.php path.

Revert changes

Temporarily revert to the original admin-ajax.php path to determine if the path change is the cause of the issue.

Elementor Shows an Error When Saving Changes After Changing the Ajax Path

If page builders like Elementor, Divi, or Bricks show an error when saving the changes, follow these steps:

Clear all cache

If you have a cache plugin or use server caching, clear all the cache, as the change of paths has significantly changed the website’s structure.

Run a Frontend Test

Go to WP Ghost > Change Paths, click the Frontend Test button (on the sidebar), and follow the server configuration instructions, if any.

Frontend test fail
Permalink settings

Go to your WordPress dashboard, navigate to Settings > Permalinks, and click Save Changes to refresh the permalinks. This action can sometimes help resolve issues related to URL structures.

Save settings permalink
Relogin to admin

If you also changed the wp-admin path together with the admin-ajax.php path, you need to log out and log in to your website to access the new admin path properly.

Revert changes

Temporarily revert to the original admin-ajax.php path to determine if the path change is the cause of the issue.

Post Editor Shows an Error When Saving Changes After Changing the Ajax Path

If you get any errors when saving the post or page in WordPress dashboard, follow these steps:

Clear all cache

If you have a cache plugin or use server caching, clear all the cache, as the change of paths has significantly changed the website’s structure.

Run a Frontend Test

Go to WP Ghost > Change Paths, click the Frontend Test button (on the sidebar), and follow the server configuration instructions, if any.

Frontend test fail
Permalink settings

Go to your WordPress dashboard, navigate to Settings > Permalinks, and click Save Changes to refresh the permalinks. This action can sometimes help resolve issues related to URL structures.

Save settings permalink
Relogin to admin

If you also changed the wp-admin path together with the admin-ajax.php path, you need to log out and log in to your website to access the new admin path properly.

Revert changes

Temporarily revert to the original admin-ajax.php path to determine if the path change is the cause of the issue.