Why does the login lock and blacklist on the website behind the proxy recognize the source address incorrectly?
Why does the login lock and IP blacklist recognize the wrong source address when the website is hosted behind a reverse proxy, the root cause is that two layers of addresses are treated as one layer.When connected directly, the program reads the visitor's address from the connection itself, the two layers overlap, and no problem can be seen. After adding a layer of proxy or gateway in front, the endpoint of the connection becomes the proxy, and the real visitor's address can only be passed through by the proxy written into the forwarding header.These two clues are one that is determined during the handshake and cannot be altered by the other party, and one that is transmitted in text form, whatever the person making the request wants to write. Once the code treats them as the same type of information, the object begins to misalign.
The two levels of addresses are not the same thing to begin with
The first layer is the connection layer source. It is determined by the transport layer, and the program receives the 'who established this TCP connection with me'. After attaching a proxy, this value steadily points to the address of the proxy itself, and the same source in the logs comes from this. The second layer is the claimed layer source, commonly in the form of headers like X-Forwarded-For, whose content is appended by the front-end node to describe 'where did the initial request come from'. It can be used, but its availability depends on whether the link is trustworthy: if the request passes through an attacker-controlled node before entering the site, then this claim can completely be forged.
The judgment logic needs to distinguish between these two things: the source of the connection layer is evidence, and the source of the claim layer is testimony. Using testimony as evidence is equivalent to allowing the visitor to fill in their identity themselves.
What will happen if we unconditionally trust the source head?
The code that causes problems is straightforward: when the program retrieves the address, it first looks at the forwarding header and uses whatever is in it, without checking if this jump is the proxy of its own, nor does it care how many segments have been chained. PbootCMS has fixed this type of problem in the update records of V3.2.25 - the address retrieval function unconditionally trusts X-Forwarded-For, leading to IP whitelist and login lock bypass, and the same version added the configurable item of trusted proxy.
The consequences are specifically in two places. Login locking is based on the cumulative number of failed attempts from the source address, the address can be self-reported, and the attacker changes a value each time, so the count never falls on the same person, and the lock is as good as none. The blacklist is the opposite, a means of banning, banning the real endpoint, but the field used for judgment is伪造的, so the real address is still used, and the false address is mistakenly injured. The common defect of the two is the same: using an editable field as an identity identifier.
Only take the most可信 value in the可信 chain.
The common practice is to declare the trusted proxy segment first, and then decide from which segment to take values. When a request goes through multiple proxy levels, multiple addresses will be stringed out in the forwarding header, with the ones on the leftmost likely being filled in by the visitor, and the ones on the rightmost being closer to the control of the next hop. Therefore, the rule for taking values should be from right to left, with the first address that does not belong to the trusted proxy segment being the source. Any content written by the jump not on the trusted list should not be trusted at all, and the address at the connection layer should be returned.
The premise of this rule is to configure 'Who is my proxy' as an explicit fact, rather than by inference. The configuration item may appear in the program, in the gateway, and both places need to be changed to be considered complete; if only one layer is changed, the other layer will still be valued according to the old rules, and the divergence between the log and the judgment will continue.
Which layer should be used for speed limit and lock?
The function of penalizing according to the source, the address level used depends on the target of the penalty. Limiting brute force attempts, banning misuse of sources, the target is the real initiators, therefore, the address after the credible link is restored should be used; For the overall throttling of a certain entrance, the object is this channel entering the site, and using the connection layer address is more stable. Mixing the two types in a switch often results in mistakenly locking a large number of normal users from the same source, while the actual high-frequency attempts recover after changing a self-reported value.
The same address also depends on which layer the field is written to in the log. During troubleshooting, only the address at the connection layer is considered, but it is determined using the claimed layer address, which does not match on both sides, causing distortion in both reproduction and statistics.
Common questions
Question: Isn't it more convenient to delete the entire forwarding header?Answer: After deleting it, only the address at the connection layer remains, and the determination will degrade to 'collectively handling by proxy address', which will cause greater damage. The correct approach is to retain and configure a trusted network segment, rather than canceling this layer of information.
Question: If there is only one self-built proxy layer, do you still need to configure a trusted network segment?Answer: Yes. The role of the trusted segment is to confirm that this hop is worth trusting, regardless of the number of layers. After configuration, the rules for taking values have a basis, and it does not need to be rederived when adding a cache or gateway layer in the future.
Question: If the program is changed, do we need to make changes to the gateway?Answer: Yes. The address is written by the front-end node and read by the program, and the agreement at both ends needs to be changed before it takes effect. When only the program is changed, whether the front-end node needs to be appended and how the appending format is still in the old state.