I have been researching various techniques for preventing CSRF attacks, such as SOP, SameSite
, Secure
, Referer
validation, and CSRF Tokens, and their potential bypasses. During my research, I discovered the following vulnerabilities:
- A website's subdomain or sibling domain is vulnerable to XSS or HTML Injection. For instance:
- Subdomain:
a.com
andvulnerable.a.com
- Sibling:
a.a.com
andvulnerable.a.com
- Subdomain:
- A subdomain takeover (SDTO) attack
- A Man-in-the-middle (MITM) attack
However, I'm unsure if correctly implemented Signed Double Submit Cookie and Referer
validation are vulnerable to those?
What I mean by correctly implemented:
- With Signed Double Submit is meant a session-bound and signed (HMAC) CSRF token, stored in a non-
HttpOnly
cookie with theSecure
flag. - With
Referer
validation is meant a Strict (block requests that have noReferer
header) and Strong (handles subdomain and URL queries)Referer
validation.
Questions:
Is Signed Double Submit Cookie & Strict & Strong
Referer
validation vulnerable to MITM?According to this SO answer:
... If an application is hosted at
https://secure.example.com
, even if the cookies are set with the secure flag, a man in the middle can force connections tohttp://secure.example.com
and set (overwrite) any arbitrary cookies (even though the secure flag prevents the attacker from reading those cookies)...If I read this correctly, this would mean that a MITM can initiate requests from
http://b.com
tohttp://a.com
, but make the request look like it came fromhttp://a.com
. If that is true, then:- Signed Double Submit Cookie is vulnerable. The attacker doesn't even need to overwrite the CSRF cookie, since the original one is passed along automatically
- Strict & Strong
Referer
validation is vulnerable. The request, even if made fromb.com
has the valuea.com
as theReferer
value.
Is Signed Double Submit Cookie vulnerable to a vulnerable subdomain?
If an attacker gains access tovulnerable.a.com
, they can read and write any cookie.Is it true that only cookie prefixes prevent such an attack, or am I missing something where the Signed Double Submit Cookie pattern would prevent this?
Is Strict & Strong
Referer
validation vulnerable to vulnerable subdomain?
Let's look over some facts:- The
Referer
header is a forbidden header name meaning it cannot be changed programmatically. - The session cookie or JWT are commonly protected with the
HttpOnly
flag, preventing the attacker from reading or writing to it, even on subdomains.
With that in mind, does this mean that Strict & Strong
Referer
validation is not vulnerable to vulnerable subdomains?- The
Is OWASP's recommendation false?
The Signed Double Submit Cookie pattern is categorized as a mitigation technique. The Strict & StrongReferer
validation pattern is only categorized as a Defence in Depth (DiD) technique.Depending on the above questions, it may seem that only a combination of a Signed Double Submit Cookie and Strict & Strong
Referer
validation is a true mitigation technique, while alone both are DiD's?