-
Notifications
You must be signed in to change notification settings - Fork 822
[history server] Add redirect capability to enter_cluster #5086
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "math" | ||
| "mime" | ||
| "net/http" | ||
| "net/url" | ||
| "path" | ||
| "sort" | ||
| "strconv" | ||
|
|
@@ -311,6 +312,25 @@ func routerLogical(s *ServerHandler) { | |
|
|
||
| } | ||
|
|
||
| // isSafeRedirectPath reports whether target is a safe site-local redirect | ||
| // destination, guarding against open-redirect attacks. Only same-origin | ||
| // absolute paths are allowed: the value must start with a single "/", must not | ||
| // be protocol-relative ("//host") or a backslash variant ("/\host"), and must | ||
| // not carry a URL scheme or host component. | ||
| func isSafeRedirectPath(target string) bool { | ||
| if target == "" || target[0] != '/' { | ||
| return false | ||
| } | ||
| if strings.HasPrefix(target, "//") || strings.HasPrefix(target, "/\\") { | ||
| return false | ||
| } | ||
| u, err := url.Parse(target) | ||
| if err != nil { | ||
| return false | ||
| } | ||
| return u.Scheme == "" && u.Host == "" | ||
| } | ||
|
|
||
| func routerRayClusterSet(s *ServerHandler) { | ||
| ws := new(restful.WebService) | ||
| defer restful.Add(ws) | ||
|
|
@@ -363,6 +383,20 @@ func routerRayClusterSet(s *ServerHandler) { | |
| http.SetCookie(r2, &http.Cookie{MaxAge: 600, Path: "/", Name: COOKIE_OWNER_KIND_KEY, Value: resolvedClusterInfo.OwnerKind}) | ||
| http.SetCookie(r2, &http.Cookie{MaxAge: 600, Path: "/", Name: COOKIE_OWNER_NAME_KEY, Value: resolvedClusterInfo.OwnerName}) | ||
|
|
||
| // When a "redirect" query parameter is supplied, respond with a 302 to it | ||
| // instead of JSON. The Set-Cookie headers above still ride along on the | ||
| // redirect response, so a single navigation both establishes the cluster | ||
| // context and lands on the dashboard (e.g. /enter_cluster/...?redirect=/#/overview). | ||
| if redirect := r1.QueryParameter("redirect"); redirect != "" { | ||
| if !isSafeRedirectPath(redirect) { | ||
| logrus.Warnf("Rejecting unsafe redirect target: %q", redirect) | ||
| r2.WriteErrorString(http.StatusBadRequest, fmt.Sprintf("invalid redirect target: %q (must be a site-local path starting with '/')", redirect)) | ||
| return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cookies set on rejected redirectLow Severity Unsafe Additional Locations (1)Reviewed by Cursor Bugbot for commit d5089e4. Configure here. |
||
| } | ||
| http.Redirect(r2.ResponseWriter, r1.Request, redirect, http.StatusFound) | ||
| return | ||
| } | ||
|
|
||
| r2.WriteJson(map[string]interface{}{ | ||
| "result": "success", | ||
| "name": resolvedName, | ||
|
|
@@ -381,6 +415,7 @@ func routerRayClusterSet(s *ServerHandler) { | |
| Param(ws.PathParameter("namespace", "namespace")). | ||
| Param(ws.PathParameter("kind", "kind (raycluster, rayjob, or rayservice)")). | ||
| Param(ws.PathParameter("name", "name")). | ||
| Param(ws.QueryParameter("redirect", "optional site-local path (e.g. /#/overview); when set, respond with a 302 to it instead of JSON").DataType("string")). | ||
| Writes("")) | ||
|
|
||
| ws.Route(ws.GET("/{namespace}/{kind}/{name}/{session}").To(func(r1 *restful.Request, r2 *restful.Response) { | ||
|
|
@@ -395,6 +430,7 @@ func routerRayClusterSet(s *ServerHandler) { | |
| Param(ws.PathParameter("kind", "kind (raycluster, rayjob, or rayservice)")). | ||
| Param(ws.PathParameter("name", "name")). | ||
| Param(ws.PathParameter("session", "session")). | ||
| Param(ws.QueryParameter("redirect", "optional site-local path (e.g. /#/overview); when set, respond with a 302 to it instead of JSON").DataType("string")). | ||
| Writes("")) | ||
|
|
||
| } | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open redirect validation bypass
High Severity
isSafeRedirectPathonly rejects//and/\as prefixes, so path-traversal plus a mid-string backslash (for example after one query decode of%5c) still passes. Browsers can normalize that into a protocol-relativeLocation, enabling an open redirect despite the safety check. Go 1.26’shttp.Redirecthardening only encodes leading backslashes, so it does not close this gap.Reviewed by Cursor Bugbot for commit d5089e4. Configure here.