Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplementation of CSRF protection strategy #19

Merged
merged 4 commits into from
Sep 28, 2012
Merged

Reimplementation of CSRF protection strategy #19

merged 4 commits into from
Sep 28, 2012

Conversation

arkascha
Copy link
Contributor

As discussed on the mailinglist I reimplemented the CSRF protection code ( "[Owncloud] CSRF behaviour is annoying" )

Motivation:
the current (static) strategy has an annoying side effect: since the token expires the user gets an error and is asked to "reload" when using an OC view older than 1 hour. This is fine for most things. This happens when leaving the client for a while (having lunch...) or using apps that do not require a full page reload for every click (like the 'Shorty' app for example).
In the Shorty app I implemented a refresh strategy to pull fresh tokens to prevent that annoying problem That strategy works and appears safe to me. I was asked to implement that strategy in OC core which I did.

Details:
I tried to stick with the previous naming scheme where possible. I added two files and modified a few details. The new strategy:

  • pull a fresh token right before the current one expires (96%)
  • register that fresh token where required (currently ajax requests and EventSource)

Bugfix:
This commit also fixes Bug oc-1593 - Race condition with CSRF protection token initialization

Implementation:
The (first) token is still generated whilst evaluating the layout.user template. Alongside its lifespan is stored, that way that value is controlled from a single place in the code instead of being hard coded at various places. The new file core/js/requesttoken.js handles the token and its refreshing. It stores the token in the OC namespace and binds it to ajax requests. EventSource has been modified to use that token storage too.
A fresh token is pulled via an ajax call shortyl before the old one expire (96%). For this a new ajax backend has been implemented: core/ajax/requesttoken.php

Security:
The new strategy allows autorefreshment of the token. In my eyes this is not a security thread, since a fresh token can be generated anyway at all times simply by loading and OC view. So complex implementations can work around that protection anyway.
In the current state pulling a fresh token itself is not protected by a token. Also, in my eyes this is not a security problem, same reason. Though this can be argued about. Pulling a fresh token obviously still requires being authenticated and having a valid session.

Conclusion:
the commit implements an advanced strategy offering two advantages
1.) get rid of annoying error thrown into the users face
2.) fix race condition (bug 1593)

For questions and discussions: I often hang around at IRC #owncloud & #owncloud-dev, nick name 'arkascha'.

@LukasReschke
Copy link
Member

Looks fine for me, as this pull request fixes some bugs and shouldn't break something, I'm totally fine with merging this already for 4.5.

Anyone against it?

Btw. I'm really impressed of this pull request description, thank you very much Christian for doing this!

@ghost ghost assigned LukasReschke Sep 28, 2012
@@ -155,9 +155,6 @@ public function __construct( $app, $name, $renderas = "" ) {
$this->renderas = $renderas;
$this->application = $app;
$this->vars = array();
if($renderas == 'user') {
$this->vars['requesttoken'] = OC_Util::callRegister();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and L367 breaks some apps which do things like:
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>">

IMHO, you shouldn't remove these vars.
(Just commit a new version to your repository and this pull request will get updated.)

… containing the request token (currently the contacts app and maybe some 3rd party implementations)
LukasReschke added a commit that referenced this pull request Sep 28, 2012
Reimplementation of CSRF protection strategy
@LukasReschke LukasReschke merged commit cfc9839 into owncloud:master Sep 28, 2012
@lock lock bot locked as resolved and limited conversation to collaborators Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants