nextcloud / user_saml

:lock: App for authenticating Nextcloud users using SAML https://apps.nextcloud.com/apps/user_saml
https://portal.nextcloud.com/article/configuring-single-sign-on-10.html
GNU Affero General Public License v3.0
96 stars 75 forks source link

SAMLController::selectUserBackEnd(): Argument #1 ($redirectUrl) must be of type string, null given #904

Closed solracsf closed 1 week ago

solracsf commented 1 week ago

How to use GitHub


Log file

{
  "reqId": "raLF59j6eZyEbGykrBOJ",
  "level": 3,
  "time": "2024-11-15T19:23:24+01:00",
  "user": "--",
  "app": "index",
  "method": "GET",
  "url": "/apps/user_saml/saml/selectUserBackEnd",
  "message": "OCA\\User_SAML\\Controller\\SAMLController::selectUserBackEnd(): Argument #1 ($redirectUrl) must be of type string, null given, called in /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php on line 230 in file '/var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php' line 568",
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
  "version": "28.0.12.2",
  "exception": {
    "Exception": "Exception",
    "Message": "OCA\\User_SAML\\Controller\\SAMLController::selectUserBackEnd(): Argument #1 ($redirectUrl) must be of type string, null given, called in /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php on line 230 in file '/var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php' line 568",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
        "line": 184,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "__class__": "OCA\\User_SAML\\Controller\\SAMLController"
          },
          "selectUserBackEnd"
        ]
      },
      {
        "file": "/var/www/nextcloud/lib/private/Route/Router.php",
        "line": 315,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\User_SAML\\Controller\\SAMLController",
          "selectUserBackEnd",
          {
            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
          },
          {
            "_route": "user_saml.SAML.selectUserBackEnd"
          }
        ]
      },
      {
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 1069,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "/apps/user_saml/saml/selectUserBackEnd"
        ]
      },
      {
        "file": "/var/www/nextcloud/index.php",
        "line": 39,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": []
      }
    ],
    "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 169,
    "Previous": {
      "Exception": "TypeError",
      "Message": "OCA\\User_SAML\\Controller\\SAMLController::selectUserBackEnd(): Argument #1 ($redirectUrl) must be of type string, null given, called in /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php on line 230",
      "Code": 0,
      "Trace": [
        {
          "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 230,
          "function": "selectUserBackEnd",
          "class": "OCA\\User_SAML\\Controller\\SAMLController",
          "type": "->",
          "args": [
            null
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 137,
          "function": "executeController",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->",
          "args": [
            {
              "__class__": "OCA\\User_SAML\\Controller\\SAMLController"
            },
            "selectUserBackEnd"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
          "line": 184,
          "function": "dispatch",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->",
          "args": [
            {
              "__class__": "OCA\\User_SAML\\Controller\\SAMLController"
            },
            "selectUserBackEnd"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Route/Router.php",
          "line": 315,
          "function": "main",
          "class": "OC\\AppFramework\\App",
          "type": "::",
          "args": [
            "OCA\\User_SAML\\Controller\\SAMLController",
            "selectUserBackEnd",
            {
              "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
            },
            {
              "_route": "user_saml.SAML.selectUserBackEnd"
            }
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/base.php",
          "line": 1069,
          "function": "match",
          "class": "OC\\Route\\Router",
          "type": "->",
          "args": [
            "/apps/user_saml/saml/selectUserBackEnd"
          ]
        },
        {
          "file": "/var/www/nextcloud/index.php",
          "line": 39,
          "function": "handleRequest",
          "class": "OC",
          "type": "::",
          "args": []
        }
      ],
      "File": "/var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php",
      "Line": 568
    },
    "message": "OCA\\User_SAML\\Controller\\SAMLController::selectUserBackEnd(): Argument #1 ($redirectUrl) must be of type string, null given, called in /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php on line 230 in file '/var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php' line 568",
    "exception": [],
    "CustomMessage": "OCA\\User_SAML\\Controller\\SAMLController::selectUserBackEnd(): Argument #1 ($redirectUrl) must be of type string, null given, called in /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php on line 230 in file '/var/www/nextcloud/apps/user_saml/lib/Controller/SAMLController.php' line 568"
  },
  "id": "6739987f80f3d"
}

Server configuration

Web server: Nginx

Database: MariaDB

PHP version: 8.2

Nextcloud version: 28.0.12

blizzz commented 1 week ago

@solracsf I suppose you can reproduce this behaviour. Do you know how/what redirects you to /apps/user_saml/saml/selectUserBackEnd?

The redirect should only happen at https://github.com/nextcloud/user_saml/blob/master/appinfo/app.php#L123-L133 and at this point $redirectUrl is at least an empty string.

solracsf commented 1 week ago

Well, i don't really know what redirects to that URI, but to reproduce, just call:

https://cloud.example.com/apps/user_saml/saml/selectUserBackEnd

instead of

https://cloud.example.com/apps/user_saml/saml/selectUserBackEnd?redirectUrl=

Without the query param ?redirectUrl=, error is trown.

Maybe pass a default value to:

https://github.com/nextcloud/user_saml/blob/236c8de473a7eb8dfb5e5db7f8aa392c8a63d333/lib/Controller/SAMLController.php#L542

like

public function selectUserBackEnd(string $redirectUrl = ''): Http\TemplateResponse {

?

blizzz commented 1 week ago

The location should not be opened without the redirect URL. So if there was another source other than manually loading it without parameter, that be of interest. For manual the default value is the way, that's right, if there was another trigger, however, the fix should not be against the symptom.

solracsf commented 1 week ago

So if there was another source other than manually loading it without parameter, that be of interest.

I can't tell. The only thing I've got were some (10+) log lines like these last week. ⛵

blizzz commented 1 week ago

So if there was another source other than manually loading it without parameter, that be of interest.

I can't tell. The only thing I've got were some (10+) log lines like these last week. ⛵

Sounds weird. Especially in this amount. Can you tell whether these are real users, or perhaps something automated?

solracsf commented 1 week ago

In the trace, user is empty and the IP of the request seems indeed an automated one (IP comes from a datacenter).

After checking logs from that IP, this is the sequence, with associated HTTP codes:

GET / 302
GET /login 302
GET /apps/user_saml/saml/selectUserBackEnd 500
GET /apps/theming/favicon 200

But if I call / i'm 302 redirected to /apps/user_saml/saml/selectUserBackEnd?redirectUrl= ...

# curl -IL cloud.example.com

HTTP/1.1 308 Permanent Redirect
location: https://cloud.example.com/

HTTP/2 302
location: https://cloud.example.com/login

HTTP/2 302
location: https://cloud.example.com/apps/user_saml/saml/selectUserBackEnd?redirectUrl=

HTTP/2 200
blizzz commented 1 week ago

Empty user is expected. Authenticated users cannot reach this endpoint. Anyhow, for some reason they strip the query part of the redirect.

Did you double check whether the IP address was trying to access other URLs as well?

It does not really make sense to infinitely run against Nextcloud's root url, unless it's a pretty poor dos attempt?

solracsf commented 1 week ago

No, no other access logs, only those 4 URLs, in that order.

blizzz commented 1 week ago

🤷