Skip to content

files_external: answer invalid user-provided credentials with HTTP 400 - #41949

Open
openefaadmin wants to merge 4 commits into
owncloud:masterfrom
openefaadmin:fix/userglobalstorages-400-on-invalid-credentials
Open

openefaadmin wants to merge 4 commits into
owncloud:masterfrom
openefaadmin:fix/userglobalstorages-400-on-invalid-credentials

Conversation

@openefaadmin

Copy link
Copy Markdown

Description

UserGlobalStoragesController::update() only catches NotFoundException around
saveBackendOptions() / manipulateStorageConfig(). When the authentication
mechanism rejects the submitted values (an InvalidArgumentException, for example
an empty username or password) or is left without usable data
(InsufficientDataForMeaningfulAnswerException), the request ends in a 500 with
no message. Both are client errors: return 400 with the message so the Files
credentials dialog and the personal storage settings can show it.

Related Issue

No open issue; found while testing a user-provided authentication mechanism
against the userglobalstorages endpoint.

Motivation and Context

A user who submits an empty password in the Files credentials dialog gets a
generic server error instead of being told what is wrong, and the server log
records a 500 for a client mistake.

How Has This Been Tested?

  • test environment: ownCloud 11.0.1 fork on PHP 8.4, SMB mount with a
    user-provided password mechanism
  • test case 1: PUT /apps/files_external/userglobalstorages/{id} with an empty
    password: before 500 with an HTML error page, after 400 with
    {"message":"Invalid credentials: ..."}
  • test case 2: same with an empty username: 400
  • test case 3: valid credentials: unchanged, 200 with the storage status

Generated with Claude Code

UserGlobalStoragesController::update() only caught NotFoundException around
saveBackendOptions()/manipulateStorageConfig(). An auth mechanism rejecting
the submitted values (e.g. an empty username or password, thrown as
InvalidArgumentException) or being left without usable data
(InsufficientDataForMeaningfulAnswerException) therefore surfaced as a 500
server error with no message for the client. Both are client errors: return
400 with the message so the Files credentials dialog and personal settings
can show it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

Signed-off-by: Scott Barbour <[email protected]>
@openefaadmin
openefaadmin requested a review from a team as a code owner October 29, 2026 02:34
@phil-davis

Copy link
Copy Markdown
Contributor

It also looks like UserStoragesController could have similar exception catching. And that has unit tests UserStoragesControllerTest.php

UserGlobalStoragesController does not seem to have any unit tests. It would be nice to add unit tests.

openefaadmin and others added 2 commits October 29, 2026 03:22
Covers index(), show() and update() of the controller that handles a user\x27s own credentials for admin-defined mounts: the admin\x27s configuration is never returned and the password is redacted; update() answers 404 for an unknown storage, 403 when the auth mechanism is not user provided, and 400 with the reason when the auth mechanism rejects the submitted credentials or is left without usable data.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Scott Barbour <[email protected]>
… reject the options

Makes the contract explicit for app authors: an auth mechanism may throw InvalidArgumentException for options it cannot accept, and files_external answers the request with HTTP 400 and the message.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Scott Barbour <[email protected]>
/**
* @see \OCA\Files_External\Controller\UserGlobalStoragesController
*/
class UserGlobalStoragesControllerTest extends TestCase {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this extend StoragesControllerTest (like UserStoragesControllerTest does).
I haven't looked at the detail, but the production classes have similar extends:

class UserStoragesController extends StoragesController {
class UserGlobalStoragesController extends StoragesController {

And the existing test class:

class UserStoragesControllerTest extends StoragesControllerTest {

// empty username or password): a client error, not a server error.
return new DataResponse(
[
'message' => (string)$this->l10n->t('Invalid credentials: %s', [$e->getMessage()])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Exceptions messages are expected to be in English. The resulting string will have a mix of languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants