oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1package home
2
3import (
4 "amadan.net/oficina/home/internal/home/sealtest"
5 "amadan.net/rastrillo/rastrillo/webauthn/authtest"
6 "net/http/httptest"
7 "net/url"
8 "strings"
9 "testing"
10)
11
12func TestIDZeroCodesPreservesReturn(t *testing.T) {
13 a := newTestApp(t)
14 s := signInFully(t, a, sealtest.CanaryAddress)
15 k := enrol(t, a, s)
16 target := "/authorize/resume"
17 w := httptest.NewRecorder()
18 writeReturn(w, target)
19 b := idJSON(t, a, "/passkey/direct/begin", nil)
20 zero := uint32(0)
21 done := idJSON(t, a, "/passkey/direct/finish", assertionBody(k, challengeFrom(t, b), authtest.Options{RPID: credentialHost, Origin: Origin, Count: &zero}), namedCookie(t, b, ceremonyCookie), w.Result().Cookies()[0])
22 if !strings.Contains(done.Body.String(), "return_to=") {
23 t.Fatal("lost original target", done.Body.String())
24 }
25 path := "/passkey/codes?return_to=" + url.QueryEscape(target)
26 page := exchangeRequest(a.App, "GET", Origin+path, "", nil, sessionCookie(done))
27 if !strings.Contains(page.Body.String(), `name="return_to" value="/authorize/resume"`) {
28 t.Fatal("codes form lost return target")
29 }
30 codes := exchangeRequest(a.App, "POST", Origin+"/passkey/codes", Origin, url.Values{"return_to": {target}}, sessionCookie(done))
31 if !strings.Contains(codes.Body.String(), `href="/authorize/resume"`) {
32 t.Fatal("no continuation after codes")
33 }
34}
35
36func TestIDCredentialReturnLocalOnly(t *testing.T) {
37 for _, value := range []string{"/passkey/enrol", "/passkey/codes", "/authorize/resume", "/dashboard/resume", operatorConfirm, resolvePath} {
38 if got := credentialReturn(value); got != value {
39 t.Fatalf("allowed return %q became %q", value, got)
40 }
41 }
42 for _, value := range []string{"https://evil.example/authorize/resume", "http:/authorize/resume", "javascript:alert(1)", "//evil.example/authorize/resume", "///evil.example", `\\evil.example`, `/\evil.example`, `/authorize\resume`, "%2f%2fevil.example", "/%2f%2fevil.example", "/%5cevil.example", "/authorize/resume?return_to=//evil.example", "/authorize/resume#//evil.example", "\n//evil.example", "/authorize/resume\r\nLocation: https://evil.example", "authorize/resume", ""} {
43 t.Run(value, func(t *testing.T) {
44 if got := credentialReturn(value); got != "/" {
45 t.Fatalf("unsafe return %q accepted as %q", value, got)
46 }
47 })
48 }
49}
50