Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: p2p scheme ignore for http. #477

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core/corehttp/corehttp_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func tokenCheckInterceptor(r *http.Request, n *core.IpfsNode) error {
return err
}
apiHost := fmt.Sprint(strings.Split(conf.Addresses.API[0], "/")[2], ":", strings.Split(conf.Addresses.API[0], "/")[4])
if filterNoNeedTokenCheckReq(r, apiHost) {
if filterNoNeedTokenCheckReq(r, apiHost, conf.Identity.PeerID) {
return nil
}
if !commands.IsLogin {
Expand All @@ -86,8 +86,8 @@ func tokenCheckInterceptor(r *http.Request, n *core.IpfsNode) error {
return nil
}

func filterNoNeedTokenCheckReq(r *http.Request, apiHost string) bool {
if filterUrl(r) || filterP2pSchema(r) || filterLocalShellApi(r, apiHost) || filterGatewayUrl(r) {
func filterNoNeedTokenCheckReq(r *http.Request, apiHost string, peerId string) bool {
if filterUrl(r) || filterP2pSchema(r, peerId) || filterLocalShellApi(r, apiHost) || filterGatewayUrl(r) {
return true
}
return false
Expand Down Expand Up @@ -134,10 +134,13 @@ func filterLocalShellApi(r *http.Request, apiHost string) bool {
return false
}

func filterP2pSchema(r *http.Request) bool {
func filterP2pSchema(r *http.Request, peerId string) bool {
if r.URL.Scheme == "libp2p" {
return true
}
if r.Host == peerId {
return true
}
return false
}

Expand Down
Loading