Sidebar: the view forms' return uses safeReturn's rule
Fable's final review of 58fd476, a Low. localReturn let control characters other than CR, LF and tab through, so "/\v/evil.example" came back as a Location some clients read as //evil.example. It is safeReturn's rule now, with "/" as the fallback. Gate: TestLocalReturnRefusesAnythingOffSite gains \v, NUL and DEL cases, which the old localReturn returned unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+11
−9
internal/mapa/frame_test.go+4 −0internal/mapa/side.go+7 −9
diff --git a/internal/mapa/frame_test.go b/internal/mapa/frame_test.go| index d227c68..9acea82 100644 |
| --- a/internal/mapa/frame_test.go |
| +++ b/internal/mapa/frame_test.go |
| @@ -14,6 +14,10 @@ func TestLocalReturnRefusesAnythingOffSite(t *testing.T) { |
| "/\\evil.example": "/", |
| "/ok\r\nSet-Cookie: x": "/", |
| "javascript:alert(1)": "/", |
| + "/\v/evil.example": "/", |
| + "/ok\x00": "/", |
| + "/ok\x7f": "/", |
| + "/": "/", |
| } |
| for given, want := range cases { |
| if got := localReturn(given); got != want { |
diff --git a/internal/mapa/side.go b/internal/mapa/side.go| index b49d7cc..c8bad7e 100644 |
| --- a/internal/mapa/side.go |
| +++ b/internal/mapa/side.go |
| @@ -2,7 +2,6 @@ package mapa |
| import ( |
| "net/http" |
| - "strings" |
| "github.com/go-chi/chi/v5" |
| ) |
| @@ -121,16 +120,15 @@ func setViewCookie(writer http.ResponseWriter, name, value string) { |
| Secure: true}) |
| } |
| -// localReturn is a path on this site, or "/". It refuses anything that |
| -// could leave it: a scheme, a host, "//", or a backslash a browser might |
| -// read as a slash. |
| +// localReturn is a path on this site, or "/". It is safeReturn's rule, |
| +// the stronger one (review L): no scheme, no host, no "//", no |
| +// backslash a browser might read as a slash, and no control character |
| +// at all, which some clients drop, turning "/\v/evil" into "//evil". |
| func localReturn(target string) string { |
| - if !strings.HasPrefix(target, "/") || |
| - strings.HasPrefix(target, "//") || |
| - strings.ContainsAny(target, "\\\r\n\t") { |
| - return "/" |
| + if safe := safeReturn(target); safe != "" { |
| + return safe |
| } |
| - return target |
| + return "/" |
| } |
| // pinned reports whether the page on screen is one of the viewer's pins. |