How serverless helps keep your WordPress site secure
Tags: serverless, wordpress, security
Published: 2021-08-17 15:56:01

---
title: How serverless helps keep your WordPress site secure
published: true
tags: serverless, wordpress, security
canonical_url: https://blog.ymirapp.com/serverless-wordpress-security/
---

<!-- wp:paragraph -->
<p>Anyone who manages WordPress sites knows how critical it is to keep them secure. Every day thousands of sites get hacked. The consequence of that are often disastrous. They range from lost income to Google blacklisting the WordPress site.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>WordPress itself has always been very secure. But we never use WordPress in a vacuum. We install themes and plugins. We need to host the WordPress site somewhere. All these are potential <a href="http://en.wikipedia.org/wiki/Vector_%28malware%29">attack vectors</a> that someone can use to hack your WordPress site.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Because of its nature, <a href="https://blog.ymirapp.com/serverless-php/">serverless PHP</a> makes a lot of these attack vectors irrelevant. This is another reason why it can be a great way to host a WordPress site. (Besides the ridiculous scaling potential.) It doesn't matter whether you're using <a href="https://ymirapp.com">Ymir</a> or not.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But how can serverless PHP can help keep your WordPress site secure? Well, the best way to understand is by going over serverless PHP architectural elements and how they affect these attack vectors.</p>
<!-- /wp:paragraph -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:heading {"level":1} -->
<h1>Code deployed to serverless PHP is essentially read only</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>With serverless PHP, you can <a href="https://twitter.com/twigpress/status/1395774346111631360">scale from 0 to thousands of connections in a minute</a>. To do that, <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> and other similar services will always use the same code that you deployed with. And that code will always be read-only on the server that executes it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This means that all vectors that rely on injecting PHP files into your WordPress installation don't work. We're talking injecting code in your themes, plugins, wp-config file, includes directory, etc. Those are all impossible because a Lambda function is read-only.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The only folder that isn't read only is <code>/tmp</code>. But even if someone injected files there, they wouldn’t be able to stick. That's because a Lambda function is ephemeral. It can exist one minute and be gone the next. Not to mention that it's only injected in one of hundreds of Lambda functions that could be running concurrently.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But for a code injection attacks to work, they need the code to actually stick to the server. And by its nature, serverless PHP doesn't allow this. This is why this whole category of attack vectors is a non-issue with serverless PHP.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's also worth noting that this also means that the plugin and theme file editors won't work. This is also another common attack vector for injecting PHP code into your WordPress site.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":1} -->
<h1>Your uploads directory isn't on a server</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Another common place for attackers to inject files is the uploads directory. You upload a file to it. And then you can just have PHP execute it by making a request to it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That's why it's a common security practice to disallow PHP file execution in the uploads directory. That way, if someone injects a PHP file and requests it, they'll just download the file instead of having PHP execute it. With serverless WordPress, this is the only possible behaviour because your upload directory isn't on a server. It's on <a href="https://aws.amazon.com/s3/">S3</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":111,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://blog.ymirapp.com/uploads/2021/05/serverless-wordpress-s3-1024x173.png" alt="" class="wp-image-111"/><figcaption><a href="https://blog.ymirapp.com/uploads/2021/05/serverless-wordpress-s3.png">Full size</a></figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Above is a diagram of the serverless WordPress architecture. (To read more on it, check out <a href="https://blog.ymirapp.com/serverless-wordpress-aws/">this article</a>.) As you can see, CloudFront sends all upload file requests to S3. They never make it to the PHP runtime that runs the PHP code.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Instead, when they make a request to that PHP file, CloudFront will just send the PHP file back. Exactly like if you requested a text file. This makes it impossible for an attacker to remotely execute a PHP file in the uploads directory.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":1} -->
<h1>Things that can still happen to you</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Serverless only really protects you from attacks that target the file system. So while serverless will remove these common attack vectors, there are still things that you should be wary about.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>SQL injection attacks</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><a href="https://en.wikipedia.org/wiki/SQL_injection">SQL injection</a> is still something you have to worry about. If you have a plugin or theme with such a vulnerability, you can still get attacked that way. The best way to prevent attacks like these is to just follow standard security best practices.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Always keep your plugins and themes up to date.</li><li>Always download them from trusted sources.</li><li>Delete plugins and themes that you aren't using.</li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Brute-force attacks</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><a href="https://en.wikipedia.org/wiki/Brute-force_attack">Brute-force attacks</a> can also still happen to you even if you use serverless. Much like with SQL injection attacks, you can protect yourself against these attacks by following security best practices.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Don't use the default "admin" username.</li><li>Use a <a href="https://en.wikipedia.org/wiki/Multi-factor_authentication">two-factor authentication</a> plugin. (There are a lot of them! This site uses <a href="https://en-ca.wordpress.org/plugins/google-authenticator/">Google Authenticator</a>.)</li><li>Use a strong and uncompromised password. (I built a <a href="https://wordpress.org/plugins/passwords-evolved/">simple plugin</a> that helps with this.)</li><li>Disable XML-RPC. (If you're doing everything else, this isn't as much of a problem.)</li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Denial-of-service attacks (DDOS)</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In a similar vein as brute force attacks, you also have <a href="https://en.wikipedia.org/wiki/Denial-of-service_attack">denial-of-service attacks</a> (DDOS). This is something you can prevent using a <a href="https://en.wikipedia.org/wiki/Web_application_firewall">web application firewall</a> (WAF). Security plugins often come with a WAF or offer one as an external service.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you're using Ymir or just running WordPress yourself on AWS, you can use <a href="https://aws.amazon.com/waf/">AWS WAF</a>. This is a full featured WAF with a lot of customizable options. That said, it also comes with a lot of <a href="https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-list.html">pre-configured rules</a> to help block known threats such as bots. But it also has a WordPress rule to block known vulnerabilities such as XML-RPC.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Ymir uses CloudFront to do page caching. If you also use CloudFront this way, you get some DDOS protection for free through <a href="https://aws.amazon.com/shield">AWS Shield</a>. This will protect you against infrastructure layer attacks, but not application layers. (Also known as <a href="https://en.wikipedia.org/wiki/Denial-of-service_attack#Application_layer_attacks">layer 7</a>.) To protect against those, you need a WAF.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":1} -->
<h1>Worry-free WordPress security</h1>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>None of what we just saw is exclusive to serverless. You can do all the things that serverless helps with using a regular server. You just need to either have access to it to configure it properly or use a WordPress host that uses security best practices.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The same goes with serverless and security plugins. There's nothing serverless does which you can't do with a security plugin. That said, security plugins are often a heavy-handed solution to security issues. They can often slow down your WordPress site significantly and cause other issues. With serverless, there's no performance impact to having a secure WordPress site.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And this is pretty much the benefit of serverless security. It's not better than what you can do yourself with a properly configured server and a security plugin. It's just a more worry-free way to keep a WordPress site secure. And there's something to be said to having that peace of mind.</p>
<!-- /wp:paragraph -->