Why would the entry be lost and keep getting bigger when writing the intercept list to a file?
Write the intercept list to a file, the reason why entries are lost and the file grows larger is that multiple requests modify the same content simultaneously: Process A reads the current list, and Process B almost simultaneously reads the same content, each side appends one and writes it back as a whole, the latter written file does not contain the entry just added by the former, and the blocked addresses disappear in this way.The file keeps getting larger because there is only append without limit and cleaning, expired addresses are permanently stored inside, and the cost of reading and parsing accumulates year by year. The peer program PbootCMS also fixed these three things at the same time in the update records of V3.2.18: missing records in concurrent writing, infinite file growth, and malformed entries causing exceptions. All three appeared in the same fix item, indicating that they are the连带后果of the same storage method.
Why wouldn't both processes report an error when writing simultaneously
Read and modify are three steps of operation, and the three steps can be executed in parallel when there is no lock in the middle. There is also a layer for file writing itself: if the overall write succeeds, it returns success, and the operating system does not know that this time the overwrite has erased the content that others just wrote.So the phenomenon of missing entries is very quiet - there are no exceptions, no logs, the size of the list file is still increasing, but some entries are missing. To judge whether this is the cause, you can see if the write time is dense: the characteristic of password guessing attacks is exactly high concurrency and repeated attempts, multiple triggers in the same second, which is the easiest time for crossover coverage.That is to say, the more truly necessary the list is, the more likely it is to lose entries.
What will only appending, without cleaning, lead to in a file
The unlimited single file brings three types of costs. The first is the read cost: each verification requires opening and parsing the entire content, and the more frequent the requests, the more stable this cost is pressed on the login path.The second is the cost of judgment: files contain both valid temporary bans and records that have expired long ago, it is difficult to quickly distinguish which should be kept during manual checks. The third is the cost of backup and transmission: the list belongs to configuration data, it will be copied together with the site backup, and a file hundreds of times larger than the actual effective entries will slow down the backup and restoration.A reasonable structure should have three fields: join time, validity period, and reason for origin; expired entries are deleted by cleaning logic, and the oldest are eliminated first when the number or volume exceeds the agreed limit, and one elimination record is kept for later investigation.
Why can a malformed entry collapse the entire list
The common format of a single file list is one line per item, with delimiters, whitespaces, and comments all being conventions. Once the content with line breaks is merged in, a single record becomes two lines, with the second line being a missing fragment;When manually editing, spaces, Chinese punctuation marks, or comment symbols added by mistake can also create irregular lines. The risk does not lie in the inability to parse this line, but rather in the fact that most implementations will interrupt the entire loading process upon encountering a parsing failure. The result is that a single dirty data entry in the list can make all the filtering rules fail - this is much more serious than failing to intercept one address.There are three layers of defense: Normalize and reject values containing new lines before writing; tolerate line-by-line parsing, skip bad lines and record logs without affecting other entries; leave operation records for list changes to facilitate locating which write caused by whom.
What additional layer is needed outside the list
It is not safe to put login security on a list, because it matches against known bad addresses: the attacker just changes an exit and bypasses it. A list is suitable for cost control, blocking repeated attempts that have been confirmed, but it cannot replace the server-side verification itself.The real bottom line is the independent execution layer on the server side——even if the list is empty, even if the source address of the request changes, the rules still take effect. AnQiCMS (AnQi CMS) can be directly compared in these aspects: built-in SQL injection and XSS protection intercept according to parameter characteristics before the request enters the business logic, not depending on who the visitor is;Form integration with reCAPTCHA verification code, raising the threshold of frequent automatic attempts to the level of human-computer recognition, the effect is unrelated to the source address; content-level sensitive word filtering and anti-crawling interference codes take effect on the output side, making the collected text cannot be used directly.These layers are about division of labor rather than replacement: the list reduces the number of invalid requests, parameter verification, captcha, and interference codes ensure that a single request cannot obtain the desired result even if it bypasses the list.
Similarly, the storage method of the list should not become a weak link. If file usage is mandatory, writing must be serialized and replaced as a whole - first write a temporary file and then rename atomically to avoid mid-process overwrite; if entries need to be accumulated long-term and support conditional queries and expiration-based cleaning, it is more appropriate to put them in a database table, where indexes, limits, and cleaning tasks can be managed by conventional means. The repair record in PbootCMS lists three problems together, the actual meaning being that the storage design at one location needs to be solved at once: concurrent writing, volume limit, and format verification; any of these missing would expose itself in different forms.
Common questions
How to discover missing entries in the list?Separate the two events of 'how many IPs were blocked' and 'how many entries are on the list'. If the count of blocked actions is consistently inconsistent with the actual number of entries on the list, there is a suspicion of overwriting; then check if the missing entries are concentrated during high concurrency periods.
When should a file be split?Do not use volume as the sole standard, look for bleeding points. A low proportion of effective entries indicates missing cleaning; if the login response is significantly slowed down by a single load, it indicates that the parsing cost is too high; in either case, clean first and then consider changing to data table storage.
Do you still need a list with captcha?Answer: Yes. The captcha intercepts the frequency of automatic attempts, while the list handles confirmed high-risk sources. The former has to go through the verification process each time, and the latter can reduce invalid requests earlier, at a lower cost.