MCPcopy Create free account
hub / github.com/imroc/req / SameDomainRedirectPolicy

Function SameDomainRedirectPolicy

redirect.go:39–46  ·  view source on GitHub ↗

SameDomainRedirectPolicy allows redirect only if the redirected domain is the same as original domain, e.g. redirect to "www.imroc.cc" from "imroc.cc" is allowed, but redirect to "google.com" is not allowed.

()

Source from the content-addressed store, hash-verified

37// is the same as original domain, e.g. redirect to "www.imroc.cc" from
38// "imroc.cc" is allowed, but redirect to "google.com" is not allowed.
39func SameDomainRedirectPolicy() RedirectPolicy {
40 return func(req *http.Request, via []*http.Request) error {
41 if getDomain(req.URL.Host) != getDomain(via[0].URL.Host) {
42 return errors.New("different domain name is not allowed")
43 }
44 return nil
45 }
46}
47
48// SameHostRedirectPolicy allows redirect only if the redirected host
49// is the same as original host, e.g. redirect to "www.imroc.cc" from

Callers 1

TestRedirectFunction · 0.85

Calls 1

getDomainFunction · 0.85

Tested by 1

TestRedirectFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…