Will the data files in the site directory be directly downloaded, and at which layer should it be blocked during deployment?
Will the database file or data directory under the website directory be directly downloaded if there is no access restriction? Yes. And where should it be blocked, the answer is both at the deployment layer and the application layer. The reason is not mysterious: when the web server processes requests, as long as the path matches a file on the disk, it will return it as static content by default, without asking 'Is this the data of the program itself'. A version fix of an open-source program has made this very clear - a new default access denial rule for the data directory has been added to prevent the SQLite database file from being directly downloaded under the default deployment.
Which files should not be accessed via the public network
Ranked from high to low risk:
| File type | Why is it in the directory | Consequences after being downloaded | Who should block |
|---|---|---|---|
| Database files or data directory | The program stores data in the site directory | Full database structure, account hashes, content taken away all at once | Add rejection rules at the deployment layer |
| Backup package | Manual or scheduled backup written in the same directory | Equivalent to the direct repository and often contains configuration | Program layer change storage path |
| configuration file | Original copy left during deployment | Connection information and key leakage | Directory permissions at the deployment layer |
| Operation log | Turn on when troubleshooting | Request path and parameter leakage, which can be used to understand the interface | Deployment layer denial |
| Temporary upload and decompression residue | Batch import interrupted and not cleaned up | Content exposure in advance | Program cleaning strategy |
The key judgment here is:Anything that can be returned as a static file is on the public network. Directory existence does not equal access, directory parseability equals access.
Why is the default deployment easy to miss this one
There are various pitfalls with the three common deployment methods. When deploying with a panel one-click, the root directory of the site is directly mapped to the Web server, and the program's data directory is naturally within the mapping range; when deploying with command line and reverse proxy, it is easy to only configure the main site's rules and forget the temporary directory written by the backup task; when deploying with Docker images, it is very common to mount the data volume for convenience and directly into the site's accessible path.
AnQiCMS is developed based on Go language, the program listens on port 8001 by default. When it goes online, if this layer of port is directly exposed to the public network without going through a reverse proxy, it is equivalent to skipping the step of 'adding interception rules at the reverse proxy layer', and the exposure surface is taken over by the program itself.
How to block at the web server layer
The approach at this layer is to add rejection rules to the directory, granularity to the path rather than to the file extension:
- The entire data directory is rejected, do not just block a certain suffix, because the backup product may change the extension name;
- Place the rejection rules in the position of matching first to avoid being hit by the general static rules first;
- After proxying, confirm that the rules have not been transmitted through - some paths only take effect when proxying to the program port;
- After adding the rules, make a request to the real address once, to see if the return is a rejection or file content, just looking at the configuration file is not enough.
What can the program layer supplement?
The deployment layer is external reinforcement, and the program layer is the root cause. Three things are worth checking:
The first, the backup location. The backup and recovery of data and static files within the site, it is necessary to confirm that the directory where the backup products are written is not accessible by the site, or it will be overwritten immediately by the rules. The second, the intermediate files of import and collection. The temporary files of bulk import unpacking and content collection, need to have a consistent cleaning time. The third, error output. When debugging is enabled, write the path information into the page, which is equivalent to drawing a map for the scanner——this is why the absolute path of the local machine should never appear in the public answers.
The directory self-inspection checklist before going online.
Go through the steps in this order: List all subdirectories under the root directory of the site, request a real filename from each one using a public network address; confirm that the returned status is a rejection rather than content; check the actual output location of the backup and temporary directories; confirm whether the default port can be directly connected; finally, store this result in the operation and maintenance records, and refer to it when deploying the next change.
Common questions
Question: Isn't it enough to rename the data directory?Answer: No. Renaming only increases the cost of guessing, any scan that can enumerate directories will cover it, and the rejection rules are the control.
Question: Is it okay to set the directory as non-listable only?Answer: No. It is forbidden to list directories only to block 'seeing what files there are', as you can still download by knowing the filenames.
Question: The panel has already added cross-site protection and directory protection, do we still need program layer protection?Answer: Yes. The panel rules only cover the directory of the site it manages, and the paths of the backup and temporary files written by the program are not within its knowledge.