The redirect address after successful login is brought by parameters, and if not verified, it may be used for what.
The redirection address after successful login is brought by parameters, this itself is a reasonable design: the user should return to the original page after being required to log in from a page. The problem lies in the fact that this parameter is completely provided by the outside, and when it is not verified, the attacker only needs to replace it with his own address. This kind of defect is usually called open redirect, it does not change a line of code logic, just replacing 'intra-site address' with 'any address'.
What will be done without verification
The first usage is a phishing jump page. The domain of the link is real, but the path and query string are fake, and the user sees a familiar main domain in the address bar, the login page is also indeed real, but after logging in, it falls onto a fake page, which continues to ask for secondary verification information or诱导下载. Because the jump is initiated by the trusted site itself, the credibility judgment of the link in emails and instant messaging is also easier to pass.
The second usage is配合脚本协议。If the script prefix is allowed, the page does not leave the current domain, but executes the external code provided within the current domain, and the consequences are borne by the logged-in session. You can see these two things written into the same fix in the public version records: PbootCMS records「Fixing member login backurl open redirect and javascript: XSS, centralized verification and safe output of jump URL」in V3.2.24.
The third method is to bypass audit. Some sites attach behavior statistics and source judgment after login to the jump parameters, and the replacement of parameters means that subsequent actions also fall into the wrong context.
Concentrate on checking which types of values need to be blocked.
The check points should be centralized, not scattered in the template. The template can have its own style, but the judgment of jump address can only be one place.
There are roughly four types of values that need to be blocked:
- Absolute address: external addresses with protocol and host, all require returning to the domain names within the whitelist; different subdomains under the same domain must also be listed explicitly, not relying on suffix matching.
- The relative writing of the protocol: The writing starting with double slashes is parsed as an external host, which is the most common leak point.
- Script prefix: Any value starting with the script protocol should not be a target for jump, it should be discarded directly and return to the default address.
- Encoding deformation: The pseudo-writing composed of multi-layer percentage encoding, white space characters, and control characters should be normalized first before judgment, judged and then output, and re-encoded according to the target context when outputting.
After the verification is passed, there is still one step: output this address safely. Piling the already verified values directly into the script or properties is equivalent to invalidating the previous verification; AnQiCMS has done defense against SQL injection and cross-site scripting at the content layer, and built-in JWT authentication to ensure that the session identifier is not forged. These two solutions address different levels of problems and are indispensable.
The other two defenses on the login chain
The redirect verification manages where to go after logging in, and there are two more sections to manage. The form side接入reCAPTCHA verification code is used to distinguish between real humans and batch scripts, it blocks automated attempts and does not replace password verification; another layer in is frequency control and failure limit, to avoid the same batch of accounts being repeatedly tested.
There is one thing that needs to be clarified: anti-collection and interference codes are aimed at content being batched, and are not on the same path as login redirection, do not configure the two as the same type of protection.
Common questions
Isn't it enough to just use relative paths?Relative paths can block external hosts, but they cannot block the injected content in the page after in-site jump; still need to verify the path segment to avoid falling on unexpected pages.
Where should the whitelist be configured?Configured in the project or site settings, read by the program, do not hardcode in the template. In the case of multi-site scenarios, the back jump domains of each site are different, and the whitelist should follow the site.
Do you need to verify the login status after the check?Yes. The validity of the jump address does not mean that the current session has the right to access the target page, and the two things should be judged separately.