mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 16:15:49 -06:00
[GH-ISSUE #3480] HTTP代理设置BasicAuth鉴权后,无法通过CORS验证的问题 #2782
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#2782
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rty813 on GitHub (Jun 6, 2023).
Original GitHub issue: https://github.com/fatedier/frp/issues/3480
Bug Description
浏览器在发起跨域请求时,会先发送一个preflight预检请求。该请求是浏览器自动请求的,无法设置Authorization头,导致frp鉴权失败。失败后,请求并不送到我的后端服务器,而是由frp直接返回一个401响应。而这个响应中,并未包含Access-Control-Allow-Origin头,导致后续的请求认为跨域错误,导致无法请求成功。
frpc Version
0.49.0
frps Version
0.34.0
System Architecture
linux/arm/v7
Configurations
frpc http -s xxxxxxxxxxx -l 5000 -d xxxxxxxxxxxx --http_user xxxxxx --http_pwd xxxxxxxx --bandwidth_limit 200KB --locations /$(hostname) -n $(hostname)
Logs
No response
Steps to reproduce
...
Affected area
@fatedier commented on GitHub (Jun 7, 2023):
不太了解相关的背景,你期望的解决方案是什么?以及是否有其他的被广泛使用的代理提供了相应的可参考的解决方案,比如 nginx?
@realmx commented on GitHub (Jun 7, 2023):
我也遇到了同样的问题,正常穿透并通过nginx代理是没问题的,但是加了http_user/http_pwd就不行了
@rty813 commented on GitHub (Jun 9, 2023):
期望可以设置Frp在遇到HttpAuth验证失败时,可以自定义401错误响应的Header,增加跨域相关的头。目前我临时的做法是,取消frp的httpAuth,而是在我自己的后端服务中添加auth验证,如果校验错误,后端服务自己在401响应中添加对应的头。
@rty813 commented on GitHub (Jun 9, 2023):
nginx应该可以通过下列方式,为401响应添加头:
nginx add headers when returning 400 codes
@fatedier commented on GitHub (Jun 9, 2023):
@rty813 如果默认就附加上
Access-Control-Allow-Originheader 会有安全风险吗?是否是一个标准的做法?@rty813 commented on GitHub (Jun 9, 2023):
这个会有一定的安全风险,对于我的使用场景下,是可以这样的,但是作为一个通用的方法应该允许用户自行设定。
@fatedier commented on GitHub (Jun 9, 2023):
可以考虑支持添加返回特定 header 的功能来解决这个问题。但是这方面的能力还是有限的,复杂的需求后面还是需要依赖 nginx 之类的代理解决。
@rty813 commented on GitHub (Jun 13, 2023):
嗯嗯,如果能支持返回特定header就好了,感谢
@gocnpan commented on GitHub (Aug 18, 2023):
其实是http请求处理顺序的问题,可以在所有请求前(不校验权限)处理预检请求:以gin框架为例