fix(32.2): WR-02 refuse a ConsentPath that is not a same-origin path
Add wristband.CheckConsentPath (additive, for hosts to call at boot) and make Authorize answer 500 before storing a pending request while the configured path fails it, so the handoff can never leave the issuer's origin.
This commit is contained in:
@@ -161,6 +161,13 @@ func (s *Server) Authorize(w http.ResponseWriter, r *http.Request) {
|
||||
dataScopes = append(dataScopes, sc)
|
||||
}
|
||||
|
||||
// A ConsentPath that is not a same-origin absolute path could send the
|
||||
// browser, with the pending request id, off the issuer's origin; refuse
|
||||
// before storing anything (fail closed, CheckConsentPath).
|
||||
if err := CheckConsentPath(s.opts.ConsentPath); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
requestID, err := s.randomBytes(32)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
@@ -196,6 +203,27 @@ func (s *Server) Authorize(w http.ResponseWriter, r *http.Request) {
|
||||
writeRedirectHTML(w, http.StatusFound, spa)
|
||||
}
|
||||
|
||||
// CheckConsentPath reports why p cannot be Options.ConsentPath, or nil. The
|
||||
// path is appended to Issuer as given, so it must be an absolute path on
|
||||
// the issuer's origin: it starts with one "/" (not "//"), and carries no
|
||||
// "?", "#", "\", "@", whitespace or control character, any of which could
|
||||
// move the handoff to another host or break its query. An empty path (the
|
||||
// PHP "/connect") is valid. A host calls it at boot to refuse a bad
|
||||
// configuration early; Authorize answers 500 instead of redirecting while
|
||||
// the configured path fails it.
|
||||
func CheckConsentPath(p string) error {
|
||||
if p == "" {
|
||||
return nil
|
||||
}
|
||||
if !strings.HasPrefix(p, "/") || strings.HasPrefix(p, "//") {
|
||||
return fmt.Errorf("wristband: ConsentPath %q must be an absolute path starting with a single /", p)
|
||||
}
|
||||
if strings.ContainsAny(p, "?#\\@") || strings.ContainsFunc(p, func(r rune) bool { return r <= ' ' || r == 0x7f }) {
|
||||
return fmt.Errorf("wristband: ConsentPath %q must be a plain same-origin path", p)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// consentPath is the path the authorize handoff appends to Issuer:
|
||||
// Options.ConsentPath, or the PHP "/connect" while it is empty.
|
||||
func (s *Server) consentPath() string {
|
||||
|
||||
Reference in New Issue
Block a user