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

Prevent passwords being set with empty strings #32261

Merged
merged 1 commit into from
Sep 5, 2018

Conversation

settermjd
Copy link
Contributor

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?

  • Unit tests have been added to cover the changes.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

*/
public function setPassword($uid, $password) {
if (empty($password)) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feedback addressed @PVince81.

@codecov
Copy link

codecov bot commented Aug 7, 2018

Codecov Report

Merging #32261 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Flag Coverage Δ Complexity Δ
#javascript 52.89% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 65.37% <100%> (ø) 18670 <2> (+9) ⬆️
Impacted Files Coverage Δ Complexity Δ
lib/private/User/Database.php 72.5% <100%> (+0.46%) 44 <0> (+1) ⬆️
lib/public/Util.php 57.75% <100%> (+0.68%) 79 <2> (+2) ⬆️
lib/private/User/User.php 88.88% <100%> (+0.75%) 74 <0> (+6) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 364af70...1424934. Read the comment docs.

@settermjd settermjd force-pushed the stop-setting-empty-passwords branch from b36c1f7 to 14ad9cf Compare August 7, 2018 10:52

namespace OC\Traits;

trait EmptyStringTrait {
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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

Copy link
Contributor

@PVince81 PVince81 Aug 21, 2018

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

*/
public function setPassword($uid, $password) {
if ($this->isEmpty($password)) {
throw new ArgumentNotSetException('Password cannot be empty');
Copy link
Contributor

Choose a reason for hiding this comment

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

we usually use \InvalidArgumentException

Copy link
Contributor

@PVince81 PVince81 left a 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

/**
* @return array A list of items equivalent to an empty password value
*/
public function providesEmptyPasswordData() {
Copy link
Contributor

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

Copy link
Contributor Author

@settermjd settermjd Aug 21, 2018

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!

@settermjd
Copy link
Contributor Author

@PVince81, is it ok to go now?

Copy link
Contributor

@PVince81 PVince81 left a 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

@settermjd
Copy link
Contributor Author

@PVince81, the function's been moved. Thanks for the push.

@PVince81
Copy link
Contributor

PVince81 commented Sep 4, 2018

please fix the styles, see https://drone.owncloud.com/owncloud/core/10097/69 or run make test-php-style

@PVince81
Copy link
Contributor

PVince81 commented Sep 4, 2018

@ownclouders rebase

@ownclouders
Copy link
Contributor

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 ⚠️

@ownclouders ownclouders force-pushed the stop-setting-empty-passwords branch from d395407 to e3e358d Compare September 4, 2018 19:31
@ownclouders
Copy link
Contributor

Automated rebase with GitMate.io was successful! 🎉

@PVince81 PVince81 force-pushed the stop-setting-empty-passwords branch from e3e358d to 8a04a79 Compare September 4, 2018 20:58
@PVince81
Copy link
Contributor

PVince81 commented Sep 4, 2018

squashed. I hope this will also nudge Drone

@PVince81
Copy link
Contributor

PVince81 commented Sep 4, 2018

stable10: #32581

hopeful that there were no more testing issues then...

@phil-davis
Copy link
Contributor

Some drone problem in the install-server step of all the sub-jobs. I restarted drone just now.

@settermjd
Copy link
Contributor Author

@PVince81, do you still want #32261 (comment) done?

@PVince81
Copy link
Contributor

PVince81 commented Sep 5, 2018

@settermjd I already fixed those myself

@PVince81
Copy link
Contributor

PVince81 commented Sep 5, 2018

restarted the builds

@PVince81
Copy link
Contributor

PVince81 commented Sep 5, 2018

seems rebasing did not help:

federatedfilesharing enabled
+ php occ a:l
Enabled:
  - comments: 0.3.0
  - dav: 0.3.2
  - federatedfilesharing: 0.3.1
  - federation: 0.1.0
  - files: 1.5.2
  - files_external: 0.7.1
  - files_sharing: 0.11.0
  - files_trashbin: 0.9.1
  - files_versions: 1.3.0
  - provisioning_api: 0.5.0
  - systemtags: 0.3.0
  - updatenotification: 0.2.1
+ php occ a:e testing
testing not found

maybe resend the PR separately ?

@settermjd
Copy link
Contributor Author

settermjd commented Sep 5, 2018

@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.
@phil-davis phil-davis force-pushed the stop-setting-empty-passwords branch from 8a04a79 to 1424934 Compare September 5, 2018 14:08
@phil-davis
Copy link
Contributor

@settermjd I rebased it locally and force pushed here. CI is running again, let's see.

@phil-davis
Copy link
Contributor

CI passing 🎆

@PVince81 PVince81 merged commit fd56631 into master Sep 5, 2018
@PVince81 PVince81 deleted the stop-setting-empty-passwords branch September 5, 2018 15:40
@lock lock bot locked as resolved and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants