mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-27 13:27:50 +08:00
commands/http: Ensure request URLs start with expected prefix
This commit is contained in:
parent
bc6938dc08
commit
446acdcdb5
@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@ -9,7 +10,11 @@ import (
|
||||
|
||||
// Parse parses the data in a http.Request and returns a command Request object
|
||||
func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
|
||||
path := strings.Split(r.URL.Path, "/")[3:]
|
||||
if !strings.HasPrefix(r.URL.Path, ApiPath) {
|
||||
return nil, errors.New("Unexpected path prefix")
|
||||
}
|
||||
path := strings.Split(strings.TrimPrefix(r.URL.Path, ApiPath+"/"), "/")
|
||||
|
||||
stringArgs := make([]string, 0)
|
||||
|
||||
cmd, err := root.Get(path[:len(path)-1])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user