修改IP地址获取逻辑和后台展示逻辑,以解决特定情况下的持续"验证码错误"无法登陆的情况#396
Open
NishizakiHayato wants to merge 2 commits into
Open
Conversation
当XFF等响应头是多个IP地址时,例如阿里云ESA的: X-Forwarded-For: x.x.x.x, y.y.y.y 原有处理流程会将"x.x.x.x, y.y.y.y"整个字符串作为IP地址进行校验和存储,但是当y.y.y.y作为CDN源站发生变动时,验证会失败,显示"验证码错误"。 本次修改改进了获取流程,并加入了IP地址合法性校验,使得能够稳定的进行验证码输入和验证。
原有IP地址修改后,会出现后台显示的和程序实际获取到的不一致的i情况,因此对后台IP地址的展示逻辑进行修改以进行适配。
|
我这边也用了你的改动,完美避免需要反复登录的问题 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
原有的IP地址获取逻辑存在缺陷。当阿里云ESA等CDN传入的请求头类似"x.x.x.x, y.y.y.y"时,会将整个字符串而不是单个IP地址视为一个IP地址,当y.y.y.y作为CDN节点发生变化但真实IP地址没有变化时,由于两者字符串显然不同,将导致验证失败,从而导致用户持续显示“验证码错误”,无法登陆后台页面。
新的数据验证逻辑为,当原始IP地址字符串存在","时,将通过","拆分字符串并取左侧第一个IP地址。同时返回前会对IP地址的有效性进行验证,如果无效则会使用REMOTE_ADDR作为回退备份。
为了避免用户在后台设置时看到的IP地址和实际上程序内部的IP地址不一致,后台展示时改为通过直接调用该函数,以此获取正确的信息。(当然该标头为空时就不显示了)
※:本次问题通过DeepSeek-V4-Pro识别,并经过人工确认,随后使用CodeBuddy对相关逻辑进行了修改。目前已在我自己的网站上进行了测试,没有发生问题。