🔒️ Protect against CSRF attacks (#5)
* 🔒️ Protect against CSRF attacks CORS and the JSON API heavily reduced the attack surface here, but especially the upload endpoints were still vulnerable to CSRF attacks. All endpoints on the API that use methods beyond GET, HEAD or OPTIONS now require the presence of a csrf token (generated by the UI on first load) AND a X-CSRF-Token header with a matching value (Double Submit Cookie), unless authorization is done through an API-Key instead of a browser session. Additionally, the SameSite attribute now is set to "Strict" by default. * 🔒️ Expand CSRF protection to plugins Plugins are currently by default *opted out* of CSRF protection, to ensure backwards compatibility with third party plugins in the field. However, in a future OctoPrint version this will become a default *opt in*. Plugin authors are advised to adjust the implementation with an explicit decision via a logged warning generated in the default implementation. Additionally, plugins that have opted out their whole plugin will generate a warning in the startup messages. A decorator to exempt individual endpoints from CSRF protection as certain workflows require (see for example the auth request in the appkeys plugin) is provided. The general rule of thumb should be to opt in and only exempt those non GET/HEAD/OPTIONS endpoints that really need to be usable without an API key or CSRF cookie/header combo. In practice, that should be pretty much non. * 🐛 Fix a left-over from a local test * 🐛 Fix wrong setting in E2E test config.yaml * 🧑💻 Set CSRF header for $.ajax as well We already ensure the header is set in the client lib and on the file upload widgets, but many third party plugins don't use the client lib but rather $.ajax directly and thus break without this. * 📝 Improve docs on CSRF protection
This commit is contained in:
1 parent
0db80dc0c9
commit
59a0c8e8d7
22 files changed
+402
-20
No files matched your search
@@ -2,6 +2,7 @@ accessControl:
|
||||
salt: zXmvzI3uWuTLkSPOEfA2ZLwn3f3sGUNS
|
||||
devel:
|
||||
enableRateLimiter: false
|
||||
enableCsrfProtection: false
|
||||
plugins:
|
||||
virtual_printer:
|
||||
enabled: true
|
||||
|
||||
Reference in new issue
Block a user