Why should the script execution permission be removed from the upload directory, and at which layer is it blocked

📅 October 10, 2026 👁️ 12

Because the upload directory meets two conditions at the same time: the file content is written from the outside, and the path can be accessed from the public network. The significance of removing the script execution permission is that even if there are script files placed in this directory, the server will only return them as static content and will not run them as programs. This type of restriction should be configured at the web server layer, which is two independent defenses, not a substitute for the file type check within the program.

Why is the upload directory a high-risk position

The attachment upload is the process of falling external bytes onto the server file system, the path is usually under the root directory of the site and can be directly requested. Once the content here can be interpreted and executed, the script written in has an entry point, which is the attack surface of this type of directory. On the program side, there are input defenses: mechanisms for defending against SQL injection and XSS within the site, as well as the handling of file types and extensions during upload, all belong to the first line of defense. The value of the second line of defense lies in not depending on the first line to not fail - validations can be bypassed, and the fact that the directory does not execute scripts has nothing to do with the file content, as long as the configuration takes effect, it will always be in place.

How to configure the matching order of blocks by path

The web server determines the order of path matching configuration blocks to decide 'who to block first'. For example, according to the nginx documentation: First, check the location defined by the prefix string, and the longest match is selected and remembered;Then check the regular expressions in the order they appear in the configuration file. The search for regular expressions stops at the first match. There is also a common pitfall: if the selected longest prefix location is marked with the ^~ modifier, the regular expression will no longer be checked against other match types.This means that the restrictions set for the upload directory may be preempted by a preceding regular expression block, or vice versa, being skipped by ^~ - the restrictions do not take effect, but the configuration is valid, and this type of issue is only exposed in the request results.

How to remove execution permissions?

The idea is to provide a separate stable match for the upload directory, and within that range, disable script interpretation: do not pass the request to the script processor, but let the script class files return as source code or static content. There are two key points in the writing. First, the path should be written as the actual disk directory, and the attachment site layered by date should cover all subdirectories; second, this match should be able to win stably, using the longest prefix or ^~ to explicitly define the priority, avoiding the order dependence on regular expressions. After the configuration is changed, first request a non-existent path to confirm that the return is as expected, then use a harmless script file to verify that it is not executed, and then delete the test file after verification.

Check the backup after modification

Handle the upload directory often accompanied by cleaning actions: find suspicious files, remove them from the site directory. The risk of this step is to delete normal attachments along with them, as attachments are part of the site data, and after accidental deletion, large areas of the front-end will appear missing images.Before taking action, first confirm that the backup is available - the backup and recovery within the site cover the site database and static files, which is the prerequisite for rolling back the cleaning operation; secondly, filter by time window instead of by file extension for batch deletion, move suspicious files to an isolated directory outside the site instead of deleting them directly, and observe for a period of time before deciding on disposal.The deployment form must also be verified: Changes to files within the image under container deployment are not persistent, the cleaning results will disappear in the new container, and the handling should fall on the storage volume or site directory.

Common questions

Question: The program has already verified the file type, do we still need to configure this layer?Answer: Yes. Verification is the first line of defense and may be bypassed; the directory does not execute scripts related to content, it is the bottom layer, and the two have different points of action.

Question: Will disabling execution affect normal image access?Answer: No. The restriction is aimed at the interpretation and execution of script files, and the reading path and response method of static resources remain unchanged. Confirm each item after modification.

Question: When cleaning the upload directory and finding a large number of unfamiliar files, what should be checked first?Answer: First, check the timestamps of these files and the access logs of the source interface to confirm whether they are normal attachments generated by collection and import or abnormal writes. Do not delete in bulk before the judgment is completed, but isolate and keep a backup first.

Related articles

When the interface is being attacked, should the speed limit be configured at the gateway layer or in the program?

Both layers are needed, but they are not blocking the same thing. The gateway layer limits speed based on source address and request rate, without looking at the business identity, and can reduce the volume before the request enters the program; the program layer knows who the caller is and what action is being taken, and can be set separately for login, comment, background, and other interfaces. Taking the nginx speed limit module as an example, the rate is represented by the number of requests per second, the default burst volume is zero, and the return code for exceeding the limit can be configured. First figure out which type of interface is being scraped, and then decide which layer to configure.

2026-10-10

The website returns 502 when opened, check the program or the gateway layer first.

First, check who sent this response. 502 means that the gateway or proxy server received an invalid response from upstream, which means that the request reached the gateway and the gateway tried to forward it, but the problem is between the gateway and the program; if the gateway cannot get any response at all, it returns a 504 or similar. Troubleshooting follows three steps: bypass the gateway and directly connect to the source station port, check the gateway error logs, and check the program process and port listening. The deployment form determines which machine to perform these three steps.

2026-10-10

Don't want the page to appear in the search results, is it marked in the page or written in the exclusion rules in the file?

What needs to be blocked is whether it is crawling or indexing. The exclusion rules in the file block crawling, so content cannot be read if the page cannot be accessed; the exclusion tags in the page block indexing, on the premise that the page can be crawled. Simply writing file exclusion rules does not mean it will not be included: if a blocked page has external links pointing to it elsewhere, it may still be included in the index due to link information. To ensure it does not appear, use page-level tags and make sure they can be crawled and read; the site's robots configuration is responsible for file-level crawling control, and the two work in conjunction.

2026-10-10

Should we block AI crawling, is it written in the exclusion rules or opened up another channel?

When controlling AI-based scraping programs, the Robots exclusion rules express intent rather than enforcement: they are issued according to the path and program identifiers, and rely on the scraping party to comply voluntarily. They cannot control addresses that have already been linked out, nor are they access control. When enforcement is needed, the focus should be on server-side authentication and the paths not being publicly readable; to prevent content from being moved in one piece, there are also interference codes and anti-crawling measures. The three things should not be mixed into one layer.

2026-10-09

What steps should be taken to follow up on the WordPress 7.1.2 fix for unauthorized reading of local files on the enterprise site?

WordPress 7.1.2 is a security version released on September 22, 2026, which fixes a unauthorized attack issue: Under certain conditions, attackers can allow the page template to parse read local PHP files outside the active theme directory, and under certain environmental prerequisites, it can develop into remote code execution. The official severity level is critical, and the fix has been rolled back to the branch that is still receiving security fixes. For enterprise stations, follow the four steps of backup, upgrade, check entry, and file review.

2026-10-10

Why does the security upgrade announcement of the peer CMS still require clearing the cache and checking the files?

The security upgrade notification of the peer system often includes two requirements unrelated to the patch: delete the runtime cache directory after the upgrade and check if there are any abnormal files in the website directory. The reason is that the patch only closes the entrance and is not responsible for clearing the consequences that have already landed - there may be pages with old content left in the cache, and files uploaded may be left in the directory. The follow-up order should be to confirm the rollback first, then upgrade, and finally clear the cache and review the files.

2026-10-10

Can read which content in the station without logging in, whether to seal it off

According to the official manual, publicly available articles, pages, and categories on the site can be read through the interface by default, while encrypted content, internal users, custom types, and metadata require identity verification to access. The closure is not to shut down the interface as a whole, but to divide the exposed range by capability domain, collect permissions by user group, add confirmation steps to writing operations, and first test the visible surface with an unlogged request.

2026-10-10

The official website says it is a permanently open-source and free website building system, what should be checked when selecting it

'Permanent open source and free' is the self-description on the official website, it should be divided into three layers to verify: cost of acquisition, usage conditions, and ability boundaries. The authorization statement of peer systems writes that it is free for commercial use, and obtaining a free domain authorization code through the official website counts as authorization and is permanent, while a common authorization code is only used for specified domains; these conditions should be verified for specific projects, and then compared with the actual content model and multi-site and multi-language capabilities needed by the corporate website.

2026-10-10