Skip to content

Allow slash in group names in provisioning API - #31463

Closed
phil-davis wants to merge 2 commits into
masterfrom
fix-slashes-in-urlparams-phil
Closed

phil-davis wants to merge 2 commits into
masterfrom
fix-slashes-in-urlparams-phil

Conversation

@phil-davis

@phil-davis phil-davis commented May 17, 2018 •

Copy link
Copy Markdown
Contributor

Description

  1. In the routes for groups, allow groupid to have any characters (including /) except for group names that end in /subadmins
  2. When creating a group, do not allow group names that end in /subadmins because that would cause conflict with being able to get the subadmins of a group.
  3. Add API acceptance tests to cover these new group name possibilities

Related Issue

#31015

Motivation and Context

The provisioning API should be able to manage groups with a slash in their name.

How Has This Been Tested?

Local API acceptance test runs, and trying stuff with curl commands.

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)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@phil-davis phil-davis added this to the development milestone May 17, 2018
@phil-davis phil-davis self-assigned this May 17, 2018
@phil-davis
phil-davis force-pushed the fix-slashes-in-urlparams-phil branch from f111c76 to 95ca2c6 Compare May 17, 2018 11:07
Comment thread apps/provisioning_api/lib/Groups.php Outdated
// Check the group exists
if (!$this->groupManager->groupExists($groupId)) {
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested group could not be found');
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, \sprintf('The requested group could not be found: %s', $groupId));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is not essential to anything - I just found it handy when trying to test all sorts of weird escaped group names, that I could see what the backend had actually received as the group name.

Comment thread lib/private/legacy/api.php Outdated
} else {
$endpointText = \sprintf(' to "%s"', $endpoint);
}
$txt = "Invalid query$endpointText, please check the syntax. API specifications are here:'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is not essential to anything - I just found it handy when trying to test all sorts of weird escaped group names, that I could see what endpoint the backend thought it received, but could not match to a route.

@phil-davis
phil-davis force-pushed the fix-slashes-in-urlparams-phil branch from 95ca2c6 to 72bfc64 Compare May 17, 2018 11:17
@codecov

codecov Bot commented May 17, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #31463 into master will decrease coverage by 0.04%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #31463      +/-   ##
============================================
- Coverage     64.06%   64.01%   -0.05%     
- Complexity    18634    18667      +33     
============================================
  Files          1176     1176              
  Lines         70142    70236      +94     
  Branches       1267     1267              
============================================
+ Hits          44934    44962      +28     
- Misses        24838    24904      +66     
  Partials        370      370
Flag Coverage Δ Complexity Δ
#javascript 52.84% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 65.28% <66.66%> (-0.06%) 18667 <0> (+33)
Impacted Files Coverage Δ Complexity Δ
apps/provisioning_api/appinfo/routes.php 100% <100%> (ø) 0 <0> (ø) ⬇️
apps/provisioning_api/lib/Groups.php 97.14% <33.33%> (-2.86%) 27 <0> (+1)
apps/federatedfilesharing/lib/Notifications.php 25.64% <0%> (+14.1%) 35% <0%> (+32%) ⬆️

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 76ce78a...3b2feee. Read the comment docs.

@phil-davis

Copy link
Copy Markdown
Contributor Author

Related attempts at this sort of thing:

PR #31224 which does some more general allowing routes that have an {id} at the end to have slashes in {id} - I have cherry-picked that code to start this PR.

PR #31017 - a different way to try and handle having a slash in the group name and escaping it it the URL.

@phil-davis

Copy link
Copy Markdown
Contributor Author

It is all a bit of a "dog's breakfast" because of the /subadmins endpoint that can follow the groupid

curl http://admin:admin@localhost:8080/ocs/v1.php/cloud/groups/company/subadmins

That could be a request to list the subadmins of a group called company, or a request to list the details of a group called company/subadmins

So I have banned creating groups with names that end in /subadmins

@phil-davis

phil-davis commented May 17, 2018 •

Copy link
Copy Markdown
Contributor Author

The API tests here are at least useful - they are what needs to pass, whatever backend code solution is done.

If this seems useful, then there also needs to be code behind the webUI private endpoint that will prevent creating group names like company/subadmins from the webUI.

@phil-davis

phil-davis commented May 18, 2018 •

Copy link
Copy Markdown
Contributor Author

Note: for Apache this requires:

AllowEncodedSlashes On

so that group names like a/slash => a%2Fslash are passed through.

That is the reason for fails in the drone acceptance tests here.

Another way around this is for the test code to not rawurlencode the / character(s). Then they should get through Apache. Code like this:

		//$group = \rawurlencode($group);
		$group = implode('/', \array_map(function ($v) {
			return \rawurlencode($v);
		}, explode('/', $group)));

That works, except when a group name contains multiple slashes - a//group-name - somewhere in the server code the multiple slashes get merged into a single slash and the backend receives the group name as a/group-name

Life would be so much easier if we ban / from group names.

@phil-davis
phil-davis force-pushed the fix-slashes-in-urlparams-phil branch from e1f6e6a to cf80197 Compare May 23, 2018 10:01
@PVince81

Copy link
Copy Markdown
Contributor

Is it possible to create a group with the name "group/../something" or something alike ?
I'm wondering how dangerous this change is

@phil-davis
phil-davis force-pushed the fix-slashes-in-urlparams-phil branch from cf80197 to ffb0000 Compare May 23, 2018 15:17
@phil-davis

Copy link
Copy Markdown
Contributor Author

I added tests to manage a group called var/../etc and they work.
I think this change will work. But I really do not like the odd requirement that a group name cannot end in /subadmins - but that comes from the ambiguity in the API that gets the subadmins of a group with any name.

#31017 is a way to allow any group name. That puts an extra layer of URL-encoding so that a client can use something like group1%252Fsubadmins to specify the group name group1/subadmins. The backend group-management code gets delivered group1%2Fsubadmins and knows that %2F is a slash.

group1%252Fsubadmins/subadmins would return the subadmins of the group named group1/subadmins.

Aaaargh!

@PVince81

PVince81 commented Aug 8, 2018

Copy link
Copy Markdown
Contributor

in general I'd expect this PR to not be necessary any more after #31224

@phil-davis

Copy link
Copy Markdown
Contributor Author

Another one for me to review in the morning - there were a lot of attempts at different ways of making all these weird group names work.

@phil-davis
phil-davis force-pushed the fix-slashes-in-urlparams-phil branch 2 times, most recently from 6411656 to 430cfd3 Compare August 23, 2018 14:27
@phil-davis

Copy link
Copy Markdown
Contributor Author

See #32430 where we can first add the test scenarios.
Then we can work out which solution seems best.

@phil-davis
phil-davis force-pushed the fix-slashes-in-urlparams-phil branch from 430cfd3 to 3b2feee Compare August 24, 2018 04:16
@phil-davis

Copy link
Copy Markdown
Contributor Author

The test scenarios have been added to master.
The code here might be one way to fix the issue.
The 2nd commit here just un-skips the relevant test scenarios so that CI will demonstrate if they pass or not. If it passes, then it will be time to decide what to do next.

@DeepDiver1975

Copy link
Copy Markdown
Contributor

As discussed in #35777 the master branch will from now on hold the ownCloud 10 codebase.

This PR targetted ownCloud 11 which is postponed to a far distant future.

Because of that I'm closing this PR and kindly ask you to re-submit this PR in a few days.

Thanks a lot for your patience

@phil-davis
phil-davis deleted the fix-slashes-in-urlparams-phil branch June 18, 2020 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants