Download this file
| 1 | package mapa |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // The view forms come back only to a path on this site (level-up §3.2): |
| 6 | // anything that could leave it falls back to Today. |
| 7 | func TestLocalReturnRefusesAnythingOffSite(t *testing.T) { |
| 8 | cases := map[string]string{ |
| 9 | "/p/abc": "/p/abc", |
| 10 | "/d/2026-11-14?x=1": "/d/2026-11-14?x=1", |
| 11 | "": "/", |
| 12 | "https://evil.example": "/", |
| 13 | "//evil.example/": "/", |
| 14 | "/\\evil.example": "/", |
| 15 | "/ok\r\nSet-Cookie: x": "/", |
| 16 | "javascript:alert(1)": "/", |
| 17 | "/\v/evil.example": "/", |
| 18 | "/ok\x00": "/", |
| 19 | "/ok\x7f": "/", |
| 20 | "/": "/", |
| 21 | } |
| 22 | for given, want := range cases { |
| 23 | if got := localReturn(given); got != want { |
| 24 | t.Errorf("localReturn(%q) = %q, want %q", given, got, want) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |