mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[GH-ISSUE #4102] 配置静态文件服务时如果使用了basicauth,手机浏览器下载文件时并没有发送Authorization header导致下载文件失败 #3235
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#3235
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 @hu198021688500 on GitHub (Mar 24, 2024).
Original GitHub issue: https://github.com/fatedier/frp/issues/4102
Bug Description
配置静态文件服务时如果使用了basicauth,手机浏览器下载文件时并没有发送Authorization header导致下载文件失败
frpc Version
0.54.0
frps Version
0.52.3
System Architecture
server linux/amd64 client windows/amd64
Configurations
serverAddr = "47.11.12.2"
serverPort = 7000
log.level = "trace"
log.maxDays = 3
proxies
name = "image_static_file"
type = "tcp"
remotePort = 2239
transport.useCompression = true
transport.bandwidthLimit = "1MB"
transport.bandwidthLimitMode = "client"
[proxies.plugin]
type = "static_file"
localPath = "G:/"
stripPrefix = ""
httpUser = "user"
httpPassword = "123"
Logs
No response
Steps to reproduce
...
Affected area
@hu198021688500 commented on GitHub (Mar 24, 2024):
修改文件
frp\pkg\util\net\http.go
type HTTPAuthMiddleware struct {
user string
passwd string
authFailDelay time.Duration
}
func NewHTTPAuthMiddleware(user, passwd string) *HTTPAuthMiddleware {
middleware := &HTTPAuthMiddleware{
user: user,
passwd: passwd,
}
func (authMid *HTTPAuthMiddleware) signIn(w http.ResponseWriter, r *http.Request) bool {
reqUser, reqPasswd, hasAuth := r.BasicAuth()
if (authMid.user == "" && authMid.passwd == "") ||
(hasAuth && util.ConstantTimeEqString(reqUser, authMid.user) &&
util.ConstantTimeEqString(reqPasswd, authMid.passwd)) {
sessionToken := uuid.NewString()
expiresAt := time.Now().Add(authMid.expires)
}
func (authMid *HTTPAuthMiddleware) auth(r *http.Request) bool {
c, err := r.Cookie("session_token")
if err != nil {
log.Debugf("get cookie error: %v", err)
return false
}
_, exists := authMid.sessions[c.Value]
if exists {
log.Debugf("exist session %s and refresh it", c.Value)
authMid.sessions[c.Value] = time.Now().Add(authMid.expires)
}
return exists
}
func (authMid *HTTPAuthMiddleware) cleanSession() {
ticker := time.NewTicker(authMid.expires)
go func() {
for {
<-ticker.C
log.Debugf("start clean session...")
for k, v := range authMid.sessions {
if v.Before(time.Now()) {
log.Debugf("delete session %s", k)
delete(authMid.sessions, k)
}
}
}
}()
}
func (authMid *HTTPAuthMiddleware) Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if authMid.auth(r) {
next.ServeHTTP(w, r)
} else if authMid.signIn(w, r) {
next.ServeHTTP(w, r)
} else {
if authMid.authFailDelay > 0 {
time.Sleep(authMid.authFailDelay)
}
w.Header().Set("WWW-Authenticate",
Basic realm="Restricted")http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
}
})
}
@fatedier commented on GitHub (Mar 28, 2024):
没有理解,发送 Authorization header 不就可以了
@hu198021688500 commented on GitHub (May 15, 2024):
使用华为p40 自带的华为浏览器,在下载文件时,浏览器不会自动发送Authorization header,有cookie,因此静态服务其接收不到认证信息,导致下载失败。 不可能自己去修改浏览器base auth的默认行为呀



正常浏览文件列表时有发送auth header
点击文件下载时没有收到auth header
@fatedier commented on GitHub (May 15, 2024):
那尝试换一个其他的浏览器?
这个问题和此项目无关,也可以给华为浏览器提交意见反馈,从根本上解决问题。