Note: This vulnerabilility has been fixed.
See: MAGNOLIA-5807 - Getting issue details... STATUS
A good resource about the vulnerability is: https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet
Referer header example: Referer:
We started work on and have a basic implementation of the token method (see above ticket) but are concerned that too many things must be changed to implement it, and that this could cause problems for existing magnolia installations. So we decided to spend some more time researching the "referer-check" approach to see if this is feasible.
Conclusion after 4 hours research
Referer checking should work against known exploits if written correctly. The four downsides i see are:
- It requires that the browser sends the referer header. Some users and companies consider this to be a privacy issue - (and potentially security issue) as the referer header contains information about the browsers history - and could have sensitive information in the form of querystring. So they may currently have browser or company proxy to strip header. Of course we could say its a requirement, but customers could take affront at that (see https://bugs.launchpad.net/launchpad/+bug/560246) Privacy is a hot topic.
- There is a new html5 meta tag to configure if the referer is sent or not.
- I think we can cover the known problems with request checking, but new browser vulnerabilities could come out (flash or other plugins) that create a hole.
- We do have to be careful to implement the referer checking properly.
- More of an image then a technical thing: On the interwebs everyone always recommends using the token approach. Its the accepted, transparent approach. People may be confused or doubtful if you implement a different approach. (See https://www.google.com/webhp?ie=UTF-8#q=csrf+referer+)
Correct Referer check:
- Strictly check the "end" of the hostname. Protect against:
- Open Redirect: http://hackersite.io/?http://demoauthor45.magnolia-cms.com/.magnolia/etc,
- Tricky Subdomain: http://demoauthor45.magnolia-cms.com.hackersite.io
- Empty Referer.
Note: There is a vulnerability with a 301 redirect, it forwards its request headers. But this would only be a vulnerability via "xss" - ie if a user of the system somehow put the link on a webpage served by the same magnolia server url. (explicitly: see 301 Redirect Attack: in Notes below.)
How to support existing installation: WhiteList? Special Code? Tokens??!?
OWASP Page: Investigate Referrer Method
Statement by Statement
- "For example, open redirect vulnerabilities can be used to exploit GET-based requests that are protected with a referer check"
- This refers to sites with a redirect destination as a parameter like http://www.vulnerable.com/redirect.asp?=http://www.links.com
- See https://www.owasp.org/index.php/Open_redirect
- So an attacker could use something like http://hackersite.io/?http://demoauthor45.magnolia-cms.com/.magnolia/etc, and a poorly written referer check might let the request through since the referer will include the domain name.
- "and some organizations or browser tools remove referrer headers as a form of data protection."
- That individual or organization would have sacrafice their privacy in this case.
- "There are also common implementation mistakes with referer checks. For example if the CSRF attack originates from an HTTPS domain then the referer will be omitted. In this case the lack of a referer should be considered to be an attack when the request is performing a state change."
- True browsing from an HTTPS page to a HTTP page strips the referer header by design (spec).
- We simply consider all requests with no referrer to be an attack.
- "For example, if the victim's domain is "site.com" then an attacker have the CSRF exploit originate from "site.com.attacker.com" which may fool a broken referer check implementation. XSS can be used to bypass a referer check."
- OK. we just need a good check, ie last part of the host.
Quote from the HTTP spec:
Because the source of a link might be private information or might reveal an otherwise
private information source, it is strongly recommended that the user be able to
select whether or not the Referer field is sent. For example, a browser client could
have a toggle switch for browsing openly/anonymously, which would respectively
enable/disable the sending of Referer and From information.
"And in addition to that we also have the fact that referring websites can remove the Referer header with tricks like META refresh"
Django uses a referer check:
Vitriol of the privacy concious / support requests from hell / this could be us:
301 Redirect Attack:
4. The victim's browser requests https://attacker.com/badstuff from the attacker's server, and sends Referer: https://launchpad.net/foo in the headers.
5. The attacker's server responds with a 301 Redirect, which redirects the victim's browser to https://bugs.launchpad.net/csrfurl
6. The victim's browser receives the redirect, requests https://bugs.launchpad.net/csrfurl from the launchpad server, and sends Referer:https://launchpad.net/foo with the request.
Most web browsers do not send the referer field when they are instructed to redirect using the "Refresh" field.
If a website is accessed from a HTTP Secure (HTTPS) connection and a link points to anywhere except another secure location, then the referer field is not sent. "Clients SHOULD NOT include a Referer[sic] header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol"
FYI: Meta tag referrer
New review by Topher 2018-04-09
There are continuing client requests for improved CSRF security:
MAGNOLIA-6865 - Getting issue details... STATUS
I think that we should implement synchronizer-token authentication on Magnolia admincentral, in addition to the existing referer checks, in order to be in compliance with the recommendations by OWASP (See Owasp recommendations.) , and to match the established best-practice in the enterprise CMS space.
Research of the Referer check
I have researched Referer based security again.
The one problem that appears legit to me is that of a "replay attack" - a request that was intended to only be made once could be triggered multiple times, which could result in unexpected, unwanted changes to content. Our current protection would not stop that.
There are four common objections to relying on referer-check alone - but I don't find the reasons convincing.
- Incorrect referer check: "There are also common implementation mistakes with referer checks." I think that we have satisfactorally avoided the mistakes.
- No referer header set: Request may not have a referer header set. We simply do not allow them access, which is acceptable for our use-case.
- Browser support: Previously, not all browsers protected the referer header properly. Now they do. Its possible that someone has installed a browser extension/plugin that does something strange, but I dont think we need to cover that case. (We could add this to our browser support page)
- Doesnt always work: There are many quotes like this "Referer checking can detect some attacks but not stop all attacks", but after much searching I find no reference to anything besides the above items - in other words things that are not a problem for us. I have seen no indication that a referer can be spoofed in a CSRF context.
Most of our competitors rely on the synchrnonizer-token approach.
The following CMS that I checked all support Token based authentication:
(As far as I can tell it is for their admin interface - but could be referring to the public website in some cases.)
- AEM (https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/csrf-protection.html) (granite - so appears to be admin-side)
- Kentico (Anything using CMSPage has support)(https://docs.kentico.com/k9/securing-websites/developing-secure-websites/cross-site-request-forgery-csrf-xsrf)
- Sitecore (https://doc.sitecore.net/speak/speak_3/speak_3/protect_against_crosssite_request_forgery) (https://stackoverflow.com/questions/39536332/what-does-the-sitecore-security-anticsrf-do-and-can-i-disable-it-on-my-content-d)
- Liferay (https://web.liferay.com/community/wiki/-/wiki/Main/Authentication+Token)
- Episerver - not totally clear - but they have a feature and provide hints to how to use ASP.net tokens (https://world.episerver.com/blogs/Per-Bjurstrom/Archive/2010/4/Using-the-CSRF-page-extension-in-CMS-6/) (https://world.episerver.com/documentation/class-library/?documentId=episerverframework/7/f1266c23-719e-2631-3f41-433a8be2d8dc)
For these I could find no clear information.
I also found several indications that the token check was something that they have added relatively recently. For example AEM had referer check before and then added the token check.
Also security scanning software is apparently looking for CSRF tokens on forms.
Ive seen these two mentioned.
- Acunetix (https://devnet.kentico.com/questions/regarding-csrf)
- HP fortify
Based on the above, I think it is most important that Magnolia is percieved well and adheres to the established best practices. While our referal protection is good, it is not generally accepted and therefore will be mistrusted in many secuirty audits. In brief - many customers and potential customers will trust the OWASP page more that they will trust our reassurances that our system is secure.