nextcloud / deck

🗂 Kanban-style project & personal management tool for Nextcloud, similar to Trello
https://apps.nextcloud.com/apps/deck
GNU Affero General Public License v3.0
1.21k stars 276 forks source link

Error 500: Internal Server Error :: API Requests #3175

Closed TannerReynolds closed 3 years ago

TannerReynolds commented 3 years ago

How to use GitHub

Describe the bug When making an API request, I get a 401 unauthorized error

To Reproduce Here is the code I am using to create a board using the node-fetch package

// Create New Board
    let baseURL = "https://my.cloud.server/apps/deck/api/v1.0"
    let boardCreate = {
        title: 'example board',
        color: Math.floor(Math.random() * 16777215).toString(16) // random hex color code
    }
    fetch(`${baseURL}/boards`, {
            method: 'POST',
            body: JSON.stringify(boardCreate),
            headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', 'Authorization': 'Basic Base64OfUsername:Password' }
    })

Expected behavior Board should be created

Screenshots N/A

Client details:

Server details **Operating system**: Ubuntu 18.04.4 **Web server:** **Database:** SQL **PHP version:** 7.2.24 **Nextcloud version:** (see Nextcloud admin page) NC 18.0.4 **Where did you install Nextcloud from:** N/A **Signing status:** N/A ``` Login as admin user into your Nextcloud and access http://example.com/index.php/settings/integrity/failed paste the results here. `No errors have been found.` ``` **List of activated apps:** ``` Enabled: - accessibility: 1.4.0 - activity: 2.11.0 - breezedark: 18.0.22 - calendar: 2.0.3 - camerarawpreviews: 0.7.3 - cloud_federation_api: 1.1.0 - comments: 1.8.0 - contacts: 3.4.3 - cospend: 1.0.2 - dav: 1.14.0 - deck: 1.2.7 - diffuse: 2.5.3 - epubreader: 1.4.2 - external: 3.5.0 - extract: 1.2.4 - federatedfilesharing: 1.8.0 - federation: 1.8.0 - files: 1.13.1 - files_external: 1.9.0 - files_lock: 19.0.0 - files_markdown: 2.2.0 - files_mindmap: 0.0.22 - files_pdfviewer: 1.7.0 - files_rightclick: 0.15.2 - files_sharing: 1.10.1 - files_trashbin: 1.8.0 - files_versions: 1.11.0 - files_videoplayer: 1.7.0 - firstrunwizard: 2.7.0 - forms: 2.2.4 - fulltextsearch: 1.4.3 - group_everyone: 0.1.5 - guests: 1.4.6 - logreader: 2.3.0 - lookup_server_connector: 1.6.0 - mail: 1.4.0 - maps: 0.1.6 - nextcloud_announcements: 1.7.0 - notifications: 2.6.0 - oauth2: 1.6.0 - ocr: 6.0.58 - password_policy: 1.8.0 - phonetrack: 0.6.3 - photos: 1.0.0 - printer: 0.0.3 - privacy: 1.2.0 - provisioning_api: 1.8.0 - recommendations: 0.6.0 - serverinfo: 1.8.0 - settings: 1.0.0 - sharebymail: 1.8.0 - spreed: 8.0.9 - support: 1.1.0 - survey_client: 1.6.0 - systemtags: 1.8.0 - tasks: 0.13.6 - text: 2.0.0 - theming: 1.9.0 - theming_customcss: 1.6.0 - twofactor_backupcodes: 1.7.0 - updatenotification: 1.8.0 - viewer: 1.2.0 - whiteboard: 0.0.2 - workflow_script: 1.3.3 - workflowengine: 2.0.0 Disabled: - admin_audit - analytics - appointments - encryption - sendent - user_ldap ``` **Nextcloud configuration:** ``` { "system": { "passwordsalt": "***REMOVED SENSITIVE VALUE***", "secret": "***REMOVED SENSITIVE VALUE***", "trusted_domains": [ "localhost", "redacted IP address", "redacted domain" ], "datadirectory": "***REMOVED SENSITIVE VALUE***", "dbtype": "mysql", "version": "18.0.4.2", "overwrite.cli.url": "http:\/\/localhost", "dbname": "***REMOVED SENSITIVE VALUE***", "dbhost": "***REMOVED SENSITIVE VALUE***", "0": "redacted ip address", "dbport": "", "dbtableprefix": "oc_", "mysql.utf8mb4": true, "dbuser": "***REMOVED SENSITIVE VALUE***", "dbpassword": "***REMOVED SENSITIVE VALUE***", "installed": true, "memcache.local": "\\OC\\Memcache\\Redis", "redis": { "host": "***REMOVED SENSITIVE VALUE***", "port": 6379 }, "instanceid": "***REMOVED SENSITIVE VALUE***", "maintenance": false, "mail_smtpmode": "smtp", "mail_smtpauthtype": "LOGIN", "mail_sendmailmode": "smtp", "mail_smtpsecure": "tls", "mail_from_address": "***REMOVED SENSITIVE VALUE***", "mail_domain": "***REMOVED SENSITIVE VALUE***", "mail_smtphost": "***REMOVED SENSITIVE VALUE***", "mail_smtpport": "25", "mail_smtpauth": 1, "mail_smtpname": "***REMOVED SENSITIVE VALUE***", "mail_smtppassword": "***REMOVED SENSITIVE VALUE***", "updater.secret": "***REMOVED SENSITIVE VALUE***" } } ``` **Are you using an external user-backend, if yes which one:** LDAP/ActiveDirectory/Webdav/...
Logs #### Nextcloud log (data/nextcloud.log) ```json { "reqId": "mfVpFjQbyXwNOXAsKP9X", "level": 2, "time": "2021-07-07T19:41:15+00:00", "remoteAddr": "redacted IP", "user": "--", "app": "core", "method": "POST", "url": "/apps/deck/api/v1.0/boards", "message": "Login failed: 'Tanner' (Remote IP: 'redacted IP')", "userAgent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", "version": "18.0.4.2", "id": "60e60728caecd" } ``` #### Browser log N/A
TannerReynolds commented 3 years ago

Got passed the unauthorized issue, now getting an error 500. Here are the logs: Exception: Argument 2 passed to OCP\User\Events\BeforeUserLoggedInEvent::__construct() must be of the type string, null given, called in /var/www/html/lib/private/Server.php on line 505

{
  "reqId": "9ABCDd7jAADsxjcoH7nu",
  "level": 3,
  "time": "2021-07-07T20:54:56+00:00",
  "remoteAddr": "redacted IP address",
  "user": "--",
  "app": "index",
  "method": "POST",
  "url": "/apps/deck/api/v1.0/boards",
  "message": {
    "Exception": "Exception",
    "Message": "Argument 2 passed to OCP\\User\\Events\\BeforeUserLoggedInEvent::__construct() must be of the type string, null given, called in /var/www/html/lib/private/Server.php on line 505",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/html/lib/private/AppFramework/App.php",
        "line": 125,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "userId": null,
            "__class__": "OCA\\Deck\\Controller\\BoardApiController"
          },
          "create"
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Routing/RouteActionHandler.php",
        "line": 47,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\Deck\\Controller\\BoardApiController",
          "create",
          {
            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
          },
          {
            "_route": "deck.board_api.create"
          }
        ]
      },
      {
        "function": "__invoke",
        "class": "OC\\AppFramework\\Routing\\RouteActionHandler",
        "type": "->",
        "args": [
          {
            "_route": "deck.board_api.create"
          }
        ]
      },
      {
        "file": "/var/www/html/lib/private/Route/Router.php",
        "line": 299,
        "function": "call_user_func",
        "args": [
          {
            "__class__": "OC\\AppFramework\\Routing\\RouteActionHandler"
          },
          {
            "_route": "deck.board_api.create"
          }
        ]
      },
      {
        "file": "/var/www/html/lib/base.php",
        "line": 1008,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "/apps/deck/api/v1.0/boards"
        ]
      },
      {
        "file": "/var/www/html/index.php",
        "line": 38,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": []
      }
    ],
    "File": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 109,
    "Previous": {
      "Exception": "TypeError",
      "Message": "Argument 2 passed to OCP\\User\\Events\\BeforeUserLoggedInEvent::__construct() must be of the type string, null given, called in /var/www/html/lib/private/Server.php on line 505",
      "Code": 0,
      "Trace": [
        {
          "file": "/var/www/html/lib/private/Server.php",
          "line": 505,
          "function": "__construct",
          "class": "OCP\\User\\Events\\BeforeUserLoggedInEvent",
          "type": "->",
          "args": [
            "*** sensitive parameter replaced ***",
            "*** sensitive parameter replaced ***"
          ]
        },
        {
          "function": "OC\\{closure}",
          "class": "OC\\Server",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/private/Hooks/EmitterTrait.php",
          "line": 100,
          "function": "call_user_func_array",
          "args": [
            {
              "__class__": "Closure"
            },
            [
              "*** sensitive parameter replaced ***",
              "*** sensitive parameter replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/Hooks/PublicEmitter.php",
          "line": 40,
          "function": "emit",
          "class": "OC\\Hooks\\BasicEmitter",
          "type": "->",
          "args": [
            "\\OC\\User",
            "preLogin",
            [
              "*** sensitive parameter replaced ***",
              "*** sensitive parameter replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/User/Session.php",
          "line": 443,
          "function": "emit",
          "class": "OC\\Hooks\\PublicEmitter",
          "type": "->",
          "args": [
            "\\OC\\User",
            "preLogin",
            [
              "*** sensitive parameter replaced ***",
              "*** sensitive parameter replaced ***"
            ]
          ]
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php",
          "line": 93,
          "function": "logClientIn",
          "class": "OC\\User\\Session",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php",
          "line": 97,
          "function": "beforeController",
          "class": "OC\\AppFramework\\Middleware\\Security\\CORSMiddleware",
          "type": "->",
          "args": [
            {
              "userId": null,
              "__class__": "OCA\\Deck\\Controller\\BoardApiController"
            },
            "create"
          ]
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 98,
          "function": "beforeController",
          "class": "OC\\AppFramework\\Middleware\\MiddlewareDispatcher",
          "type": "->",
          "args": [
            {
              "userId": null,
              "__class__": "OCA\\Deck\\Controller\\BoardApiController"
            },
            "create"
          ]
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/App.php",
          "line": 125,
          "function": "dispatch",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->",
          "args": [
            {
              "userId": null,
              "__class__": "OCA\\Deck\\Controller\\BoardApiController"
            },
            "create"
          ]
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Routing/RouteActionHandler.php",
          "line": 47,
          "function": "main",
          "class": "OC\\AppFramework\\App",
          "type": "::",
          "args": [
            "OCA\\Deck\\Controller\\BoardApiController",
            "create",
            {
              "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
            },
            {
              "_route": "deck.board_api.create"
            }
          ]
        },
        {
          "function": "__invoke",
          "class": "OC\\AppFramework\\Routing\\RouteActionHandler",
          "type": "->",
          "args": [
            {
              "_route": "deck.board_api.create"
            }
          ]
        },
        {
          "file": "/var/www/html/lib/private/Route/Router.php",
          "line": 299,
          "function": "call_user_func",
          "args": [
            {
              "__class__": "OC\\AppFramework\\Routing\\RouteActionHandler"
            },
            {
              "_route": "deck.board_api.create"
            }
          ]
        },
        {
          "file": "/var/www/html/lib/base.php",
          "line": 1008,
          "function": "match",
          "class": "OC\\Route\\Router",
          "type": "->",
          "args": [
            "/apps/deck/api/v1.0/boards"
          ]
        },
        {
          "file": "/var/www/html/index.php",
          "line": 38,
          "function": "handleRequest",
          "class": "OC",
          "type": "::",
          "args": []
        }
      ],
      "File": "/var/www/html/lib/public/User/Events/BeforeUserLoggedInEvent.php",
      "Line": 46
    },
    "CustomMessage": "--"
  },
  "userAgent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
  "version": "18.0.4.2",
  "id": "60e614a16deed"
}

Undefined offset: 1 at /var/www/html/lib/base.php#1080

{
  "reqId": "9ABCDd7jAADsxjcoH7nu",
  "level": 3,
  "time": "2021-07-07T20:54:56+00:00",
  "remoteAddr": "redacted IP Address",
  "user": "--",
  "app": "PHP",
  "method": "POST",
  "url": "/apps/deck/api/v1.0/boards",
  "message": "Undefined offset: 1 at /var/www/html/lib/base.php#1080",
  "userAgent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
  "version": "18.0.4.2",
  "id": "60e614a16ddf6"
}
TannerReynolds commented 3 years ago

Tested the same exact request on a brand new server. Running latest Ubuntu, latest NC, and latest deck. Same error, here is the log

{
  "reqId": "vfArVr4sOaPJmRxvC0cZ",
  "level": 3,
  "time": "2021-07-08T21:55:12+00:00",
  "remoteAddr": "12.48.70.194",
  "user": "--",
  "app": "index",
  "method": "GET",
  "url": "/apps/deck/api/v1.0/boards",
  "message": {
    "Exception": "Exception",
    "Message": "OCP\\User\\Events\\BeforeUserLoggedInEvent::__construct(): Argument #1 ($username) must be of type string, null given, called in /var/www/html/lib/private/Server.php on line 577",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/html/lib/private/AppFramework/App.php",
        "line": 157,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/html/lib/private/Route/Router.php",
        "line": 302,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/var/www/html/lib/base.php",
        "line": 993,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/var/www/html/index.php",
        "line": 37,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 159,
    "Previous": {
      "Exception": "TypeError",
      "Message": "OCP\\User\\Events\\BeforeUserLoggedInEvent::__construct(): Argument #1 ($username) must be of type string, null given, called in /var/www/html/lib/private/Server.php on line 577",
      "Code": 0,
      "Trace": [
        {
          "file": "/var/www/html/lib/private/Server.php",
          "line": 577,
          "function": "__construct",
          "class": "OCP\\User\\Events\\BeforeUserLoggedInEvent",
          "type": "->"
        },
        {
          "function": "OC\\{closure}",
          "class": "OC\\Server",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/private/Hooks/EmitterTrait.php",
          "line": 107,
          "function": "call_user_func_array"
        },
        {
          "file": "/var/www/html/lib/private/Hooks/PublicEmitter.php",
          "line": 41,
          "function": "emit",
          "class": "OC\\Hooks\\BasicEmitter",
          "type": "->"
        },
        {
          "file": "/var/www/html/lib/private/User/Session.php",
          "line": 444,
          "function": "emit",
          "class": "OC\\Hooks\\PublicEmitter",
          "type": "->"
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php",
          "line": 93,
          "function": "logClientIn",
          "class": "OC\\User\\Session",
          "type": "->",
          "args": [
            "*** sensitive parameters replaced ***"
          ]
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php",
          "line": 98,
          "function": "beforeController",
          "class": "OC\\AppFramework\\Middleware\\Security\\CORSMiddleware",
          "type": "->"
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 119,
          "function": "beforeController",
          "class": "OC\\AppFramework\\Middleware\\MiddlewareDispatcher",
          "type": "->"
        },
        {
          "file": "/var/www/html/lib/private/AppFramework/App.php",
          "line": 157,
          "function": "dispatch",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->"
        },
        {
          "file": "/var/www/html/lib/private/Route/Router.php",
          "line": 302,
          "function": "main",
          "class": "OC\\AppFramework\\App",
          "type": "::"
        },
        {
          "file": "/var/www/html/lib/base.php",
          "line": 993,
          "function": "match",
          "class": "OC\\Route\\Router",
          "type": "->"
        },
        {
          "file": "/var/www/html/index.php",
          "line": 37,
          "function": "handleRequest",
          "class": "OC",
          "type": "::"
        }
      ],
      "File": "/var/www/html/lib/public/User/Events/BeforeUserLoggedInEvent.php",
      "Line": 46
    },
    "CustomMessage": "--"
  },
  "userAgent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
  "version": "21.0.2.1",
  "id": "60e774546987e"
}
TannerReynolds commented 3 years ago

Any updates on this?

juliusknorr commented 3 years ago

Your example code works perfectly fine for me. The undefined offset error looks quite odd, maybe it is an issue with the base64 encoding of the username:password? Did you build that basic auth header properly with something like btoa('username:password') ?

fetch(`${baseURL}/boards`, {
    method: 'POST',
    body: JSON.stringify(boardCreate),
    headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', 'Authorization': 'Basic ' + btoa('username:password') }
})
TannerReynolds commented 3 years ago

Your example code works perfectly fine for me. The undefined offset error looks quite odd, maybe it is an issue with the base64 encoding of the username:password? Did you build that basic auth header properly with something like btoa('username:password') ?

fetch(`${baseURL}/boards`, {
  method: 'POST',
  body: JSON.stringify(boardCreate),
  headers: { 'OCS-APIRequest': 'true', 'Content-Type': 'application/json', 'Authorization': 'Basic ' + btoa('username:password') }
})

hmmmm, I was sending over plaintext as well as an already base4 encoded string. They didn't work. Your btoa method though? it works perfectly, for some reason. Thank you!