-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Prevent passwords being set with empty strings #32261
Conversation
lib/private/User/Database.php
Outdated
*/ | ||
public function setPassword($uid, $password) { | ||
if (empty($password)) { |
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 will prevent someone setting their password to the string char "0".
I guess that is not such a bad restriction on valid password strings.
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.
True. But on reading after coming to understand the code better and reading through https://github.com/owncloud/security-tracker/issues/282 in light of that information, it appears to me that this PR isn't required, as the code works as expected.
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.
Turns out, this PR's still in the game after further discussion with @PVince81.
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.
please avoid using empty()
in any case due to its nasty implicit nature.
if you intend to check for "0" then add an explicit check for it
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.
Feedback addressed @PVince81.
Codecov Report
@@ Coverage Diff @@
## master #32261 +/- ##
============================================
+ Coverage 64.09% 64.1% +<.01%
- Complexity 18661 18670 +9
============================================
Files 1177 1177
Lines 70247 70255 +8
Branches 1270 1270
============================================
+ Hits 45026 45035 +9
+ Misses 24851 24850 -1
Partials 370 370
Continue to review full report at Codecov.
|
b36c1f7
to
14ad9cf
Compare
|
||
namespace OC\Traits; | ||
|
||
trait EmptyStringTrait { |
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.
@DeepDiver1975 thoughts on this ? does PHP 7.2 bring something ?
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.
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.
@settermjd can you remove this trait ? this feels a bit overengineered
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.
maybe put this as a local method on the class then. I'd rather move this forward to get it merged than spend a long time trying to decide where this method needs to go
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.
I'm slightly reluctant as it'd have to be copied into both Database and User, as they don't share a common base class and the functionality's not logically specific to either. However, if that's the call, just say and I'll make it happen.
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.
should we then rather move it to \OCP\Util then ? then any app can use it.
a Trait feel a bit like overkill
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.
@settermjd please move this to \OCP\Util
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.
Odd, I thought I'd already done this.
lib/private/User/Database.php
Outdated
*/ | ||
public function setPassword($uid, $password) { | ||
if ($this->isEmpty($password)) { | ||
throw new ArgumentNotSetException('Password cannot be empty'); |
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.
we usually use \InvalidArgumentException
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.
sounds like a bit much adding all these new traits and classes just for this simple thing
tests/lib/Traits/PasswordTrait.php
Outdated
/** | ||
* @return array A list of items equivalent to an empty password value | ||
*/ | ||
public function providesEmptyPasswordData() { |
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.
feels like overkill to have a trait just for this
maybe we could move the test set to the TestCase
base class and put common data providers there, but then it would be providesEmptyValues()
and not specific to passwords
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.
Sounds fine to me. The main motivation was not to have duplicated code. But if having a similar method in TestCase
achieves the same objective, them I'm 💯% behind it!
@PVince81, is it ok to go now? |
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.
please move the utility function to \OCP\Util
@PVince81, the function's been moved. Thanks for the push. |
please fix the styles, see https://drone.owncloud.com/owncloud/core/10097/69 or run |
@ownclouders rebase |
Hey! I'm GitMate.io! This pull request is being rebased automatically. Please DO NOT push while rebase is in progress or your changes would be lost permanently |
d395407
to
e3e358d
Compare
Automated rebase with GitMate.io was successful! 🎉 |
e3e358d
to
8a04a79
Compare
squashed. I hope this will also nudge Drone |
stable10: #32581 hopeful that there were no more testing issues then... |
Some drone problem in the install-server step of all the sub-jobs. I restarted drone just now. |
@PVince81, do you still want #32261 (comment) done? |
@settermjd I already fixed those myself |
restarted the builds |
seems rebasing did not help:
maybe resend the PR separately ? |
@PVince81, I don't understand what you're asking in #32261 (comment). |
Previously, if an attempt was made to set a password with an, effectively, empty string the setPassword function would accept it without question. This commit prevents that from happening by throwing an exception if an empty password string is supplied. What this commit doesn't do is check any of the knock-on of upstream effects of this change. One thing to bear in mind; No test in the current test suite appears to fail as a result. That doesn't mean that everything's ok though. So further work needs to be done to ensure that no bugs appear as a result of this change.
8a04a79
to
1424934
Compare
@settermjd I rebased it locally and force pushed here. CI is running again, let's see. |
CI passing 🎆 |
Description
Currently, if an attempt is made to set a password with an, effectively, empty string it will be accepted
without question. This PR seeks to prevent that from happening, by ensuring that passwords must be set to a meaningful/valid value.
Related Issue
Motivation and Context
It prevents a user's password from being set to an empty string.
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist:
Open tasks: