Security Weekly

What is Cross-Site Request Forgery?

Cleanshot 2023 11 30 At 14.14.30

Published:

Cleanshot 2023 11 30 At 14.14.30

Oliver Sild

Patchstack

Oliver Sild is the CEO and Co-founder of Patchstack. He is an entrepreneur and cyber security expert with a strong focus on community building. He has been organising hacking competitions (& local CTF community) in Estonia since 2016, has kickstarted a startup community in his hometown and has nearly 10 years of experience with WordPress security.

Week 36

Let’s talk about Cross-Site Request Forgery. It’s a common security vulnerability that might have affected your website as well. In fact, according to the 2022 State of WordPress Security Report, Cross-Site Request Forgery was the most prevalent vulnerability type found in WordPress plugins. In 2023, it ranked second.

While Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) may sound similar, they are distinct vulnerabilities. Moreover, when combined, they can create a much more dangerous threat. To ensure you don’t fall victim to this, let’s dive into what CSRF is and why it happens.

What causes a Cross-Site Request Forgery (CSRF vulnerability?

Cross-Site Request Forgery occurs due to the absence of CSRF tokens (also known as nonces in WordPress). These unique tokens are generated by the server and are associated with the user’s session. For example, each time a form is submitted, the server checks whether the submitted token matches the expected nonce value. If a WordPress plugin or theme does not implement CSRF tokens properly, it becomes vulnerable to CSRF attacks.

In some cases, developers may also forget to include checks that verify the user’s intent to perform a particular action. If such checks are missing, an attacker could craft a request that appears legitimate to the server but is actually initiated by the attacker.

What can happen if your WordPress website has an CSRF vulnerability?

If your website is vulnerable to CSRF, an attacker can trick a logged-in user into requesting a URL that performs some kind of privileged action on the website. Such actions can include changing site settings (such as enabling user registration), modifying content, and more.

CSRF is rarely exploited actively in the wild because it requires a privileged user to be tricked into clicking on a link that includes instructions to perform some kind of meaningful action. To execute such attacks, hackers often need to combine them with social engineering tactics. The high complexity and generally low impact make this vulnerability type less attractive to hackers.

However, if your site is also vulnerable to Cross-Site Scripting (XSS), it’s a different story. Since an XSS vulnerability allows attackers to inject arbitrary code into pages on the compromised website, the attacker can now perform a CSRF attack without any user interaction. Given that XSS and CSRF are the top two most common vulnerability types found in the WordPress ecosystem, CSRF should be taken very seriously.

What can WordPress developers do to avoid CSRF vulnerabilities?

WordPress provides several functions that plugin and theme developers can use to avoid CSRF vulnerabilities. Developers can use the wp_create_nonce function to generate the nonce token. They can then verify nonces with wp_verify_nonce or use check_admin_referer, which automatically exits the script if no nonce token can be validated. It’s important to ensure the nonce check is properly implemented so that it cannot be bypassed due to flawed logic.

WordPress admins can avoid CSRF by being cautious when clicking on suspicious links that lead to their own website, particularly those directing to /wp-admin/. Monitor your website for potential vulnerabilities and pay extra attention to preventing XSS and CSRF vulnerabilities from being present simultaneously.

Conclusion

Cross-Site Request Forgery (CSRF) is a significant security threat that can lead to unauthorized actions on your WordPress site if left unaddressed. Although it may not be as commonly exploited as other vulnerabilities, its potential impact, especially when combined with Cross-Site Scripting (XSS), makes it crucial for WordPress developers and administrators to implement proper security measures.

Cleanshot 2023 11 30 At 14.14.30

Oliver Sild

Patchstack

Oliver Sild is the CEO and Co-founder of Patchstack. He is an entrepreneur and cyber security expert with a strong focus on community building. He has been organising hacking competitions (& local CTF community) in Estonia since 2016, has kickstarted a startup community in his hometown and has nearly 10 years of experience with WordPress security.

Brought to you by:
Logo

Patchstack auto-mitigates security vulnerabilities found on WordPress core, plugins and themes. Patchstack is the leading vulnerability intelligence provider in the entire WordPress ecosystem and has the largest collection of vulnerability specific vPatch rules that provide precision protection without any performance hit nor false positives. Patchstack is the go-to security provider for many of the leading agencies such as 10up, Valet, SiteCare and others.

Never Miss an Issue!

Subscribe and have Security Weekly delivered to your inbox every week!

Care Plan Toolkit

Save time, boost profits, and confidently manage client websites with proven tools, tips, and resources.

Bento Toolkit

More from Security Weekly

Week 49

Increased Volume of Threats During Holidays

We are just a few days away from Christmas holidays and many people have already gone …

Week 48

What Will WordPress Security Look Like in 2025?

I was thinking wether to leave this as the last security weekly, but I recon that …

Week 47

Why Use Virtual Patching for WordPress Security?

Virtual patching is a security strategy that involves applying protective measures to the WordPress application without …