-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Reimplementation of CSRF protection strategy #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
743826b
Reimplementation of CSRF protection including autorefresh
4dbd4c3
Merge branch 'master' of git://github.com/owncloud/core
cd399f9
Added name to AUTHORS file, since mentioned in file headers.
arkascha 71454b1
Fix to preserve backward compatibility for apps creating static links…
arkascha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
| /** | ||
| * ownCloud | ||
| * @author Christian Reiner | ||
| * @copyright 2011-2012 Christian Reiner <foss@christian-reiner.info> | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
| * License as published by the Free Software Foundation; either | ||
| * version 3 of the license, or any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with this library. | ||
| * If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| /** | ||
| * @file core/ajax/requesttoken.php | ||
| * @brief Ajax method to retrieve a fresh request protection token for ajax calls | ||
| * @return json: success/error state indicator including a fresh request token | ||
| * @author Christian Reiner | ||
| */ | ||
| require_once '../../lib/base.php'; | ||
|
|
||
| // don't load apps or filesystem for this task | ||
| $RUNTIME_NOAPPS = TRUE; | ||
| $RUNTIME_NOSETUPFS = TRUE; | ||
|
|
||
| // Sanity checks | ||
| // using OCP\JSON::callCheck() below protects the token refreshing itself. | ||
| //OCP\JSON::callCheck ( ); | ||
| OCP\JSON::checkLoggedIn ( ); | ||
| // hand out a fresh token | ||
| OCP\JSON::success ( array ( 'token' => OCP\Util::callRegister() ) ); | ||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * ownCloud | ||
| * | ||
| * @file core/js/requesttoken.js | ||
| * @brief Routine to refresh the Request protection request token periodically | ||
| * @author Christian Reiner (arkascha) | ||
| * @copyright 2011-2012 Christian Reiner <foss@christian-reiner.info> | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
| * License as published by the Free Software Foundation; either | ||
| * version 3 of the license, or any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with this library. | ||
| * If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| OC.Request = { | ||
| // the request token | ||
| Token: {}, | ||
| // the lifespan span (in secs) | ||
| Lifespan: {}, | ||
| // method to refresh the local request token periodically | ||
| Refresh: function(){ | ||
| // just a client side console log to preserve efficiency | ||
| console.log("refreshing request token (lifebeat)"); | ||
| var dfd=new $.Deferred(); | ||
| $.ajax({ | ||
| type: 'POST', | ||
| url: OC.filePath('core','ajax','requesttoken.php'), | ||
| cache: false, | ||
| data: { }, | ||
| dataType: 'json' | ||
| }).done(function(response){ | ||
| // store refreshed token inside this class | ||
| OC.Request.Token=response.token; | ||
| dfd.resolve(); | ||
| }).fail(dfd.reject); | ||
| return dfd; | ||
| } | ||
| } | ||
| // accept requesttoken and lifespan into the OC namespace | ||
| OC.Request.Token = oc_requesttoken; | ||
| OC.Request.Lifespan = oc_requestlifespan; | ||
| // refresh the request token periodically shortly before it becomes invalid on the server side | ||
| setInterval(OC.Request.Refresh,Math.floor(1000*OC.Request.Lifespan*0.93)), // 93% of lifespan value, close to when the token expires | ||
| // early bind token as additional ajax argument for every single request | ||
| $(document).bind('ajaxSend', function(elm, xhr, s){xhr.setRequestHeader('requesttoken', OC.Request.Token);}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.)