nextcloud/forms

Form submission fails if attached file is stored in a shared directory

Closed this issue · 5 comments

The form submission fails, if an attached file is stored in a directory that does not belong to the same user.

To Reproduce

  1. User A: create a directory
  2. User A: share the directory with user B
  3. User B: create a form
  4. User B: connect the form with an .ods-file
  5. User B: store the file in the directory shared by user A
  6. Fill out the form

Expected behavior
Receive a note that the form has been submitted successfully

Actual behavior
"There was an error submitting the form" popup in the browser top right.

Error notification in the logs:

[no app in context] Exception OC\Files\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/html/lib/private/Files/View.php on line 528 in file '/var/www/html/lib/private/Files/View.php' line 1128
Exception thrown: Exception

{
    "reqId": "PkumN8hN2SGi5409yMLZ",
    "level": 3,
    "time": "2024-03-21T18:08:12+00:00",
    "remoteAddr": "172.20.0.1",
    "user": "--",
    "app": "no app in context",
    "method": "POST",
    "url": "/ocs/v2.php/apps/forms/api/v2.4/submission/insert",
    "message": "Exception thrown: Exception",
    "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
    "version": "28.0.3.2",
    "exception": {
        "Exception": "Exception",
        "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/html/lib/private/Files/View.php on line 528 in file '/var/www/html/lib/private/Files/View.php' line 1128",
        "Code": 0,
        "Trace": [
            {
                "file": "/var/www/html/lib/private/AppFramework/App.php",
                "line": 184,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->",
                "args": [
                    [
                        "OCA\\Forms\\Controller\\ApiController"
                    ],
                    "insertSubmission"
                ]
            },
            {
                "file": "/var/www/html/lib/private/Route/Router.php",
                "line": 315,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::",
                "args": [
                    "OCA\\Forms\\Controller\\ApiController",
                    "insertSubmission",
                    [
                        "OC\\AppFramework\\DependencyInjection\\DIContainer"
                    ],
                    [
                        "v2.4",
                        "ocs.forms.api.insertSubmission"
                    ]
                ]
            },
            {
                "file": "/var/www/html/ocs/v1.php",
                "line": 65,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->",
                "args": [
                    "/ocsapp/apps/forms/api/v2.4/submission/insert"
                ]
            },
            {
                "file": "/var/www/html/ocs/v2.php",
                "line": 23,
                "args": [
                    "/var/www/html/ocs/v1.php"
                ],
                "function": "require_once"
            }
        ],
        "File": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "Line": 169,
        "Previous": {
            "Exception": "TypeError",
            "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/html/lib/private/Files/View.php on line 528",
            "Code": 0,
            "Trace": [
                {
                    "file": "/var/www/html/lib/private/Files/View.php",
                    "line": 528,
                    "function": "basicOperation",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args": [
                        "file_exists",
                        null
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Files/Filesystem.php",
                    "line": 545,
                    "function": "file_exists",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args": [
                        null
                    ]
                },
                {
                    "file": "/var/www/html/apps/files_versions/lib/Storage.php",
                    "line": 190,
                    "function": "file_exists",
                    "class": "OC\\Files\\Filesystem",
                    "type": "::",
                    "args": [
                        null
                    ]
                },
                {
                    "file": "/var/www/html/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 196,
                    "function": "store",
                    "class": "OCA\\Files_Versions\\Storage",
                    "type": "::",
                    "args": [
                        null
                    ]
                },
                {
                    "file": "/var/www/html/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 102,
                    "function": "write_hook",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->",
                    "args": [
                        [
                            "OC\\Files\\Node\\File"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/EventDispatcher/ServiceEventListener.php",
                    "line": 86,
                    "function": "handle",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->",
                    "args": [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 230,
                    "function": "__invoke",
                    "class": "OC\\EventDispatcher\\ServiceEventListener",
                    "type": "->",
                    "args": [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "Symfony\\Component\\EventDispatcher\\EventDispatcher"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 59,
                    "function": "callListeners",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args": [
                        [
                            [
                                "Closure"
                            ]
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 94,
                    "function": "dispatch",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args": [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 106,
                    "function": "dispatch",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args": [
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Files/Node/HookConnector.php",
                    "line": 100,
                    "function": "dispatchTyped",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args": [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/legacy/OC_Hook.php",
                    "line": 105,
                    "function": "write",
                    "class": "OC\\Files\\Node\\HookConnector",
                    "type": "->",
                    "args": [
                        [
                            true,
                            "/desktop/Vermietungsanfragen (Antworten).ods"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Files/View.php",
                    "line": 1270,
                    "function": "emit",
                    "class": "OC_Hook",
                    "type": "::",
                    "args": [
                        "OC_Filesystem",
                        "write",
                        [
                            true,
                            "/desktop/Vermietungsanfragen (Antworten).ods"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Files/View.php",
                    "line": 1144,
                    "function": "runHooks",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args": [
                        [
                            "update",
                            "write"
                        ],
                        "/desktop/Vermietungsanfragen (Antworten).ods"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Files/View.php",
                    "line": 680,
                    "function": "basicOperation",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args": [
                        "file_put_contents",
                        "/vermietung/files/desktop/Vermietungsanfragen (Antworten).ods",
                        [
                            "update",
                            "write"
                        ],
                        null
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Files/Node/File.php",
                    "line": 73,
                    "function": "file_put_contents",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args": [
                        "/vermietung/files/desktop/Vermietungsanfragen (Antworten).ods",
                        null
                    ]
                },
                {
                    "file": "/var/www/html/custom_apps/forms/lib/Service/SubmissionService.php",
                    "line": 224,
                    "function": "putContent",
                    "class": "OC\\Files\\Node\\File",
                    "type": "->",
                    "args": [
                        null
                    ]
                },
                {
                    "file": "/var/www/html/custom_apps/forms/lib/Controller/ApiController.php",
                    "line": 1113,
                    "function": "writeFileToCloud",
                    "class": "OCA\\Forms\\Service\\SubmissionService",
                    "type": "->",
                    "args": [
                        [
                            "OCA\\Forms\\Db\\Form",
                            5
                        ],
                        "/desktop/Vermietungsanfragen (Antworten).ods",
                        "ods",
                        "vermietung"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 230,
                    "function": "insertSubmission",
                    "class": "OCA\\Forms\\Controller\\ApiController",
                    "type": "->",
                    "args": [
                        5,
                        [
                            [
                                "Testgruppe 2"
                            ],
                            [
                                "Hier kommt zur allgemeinen Belustigung ein etwas längerer Text mit einem völlig überraschenden\nZeilenumbruch und irgendwelchen doofen Emojis 👋😎\n"
                            ],
                            [
                                "17"
                            ],
                            [
                                "Jeden Tag"
                            ],
                            [
                                "19",
                                "20",
                                "21",
                                "22",
                                "23",
                                "And 1 more entries, set log level to debug to see all entries"
                            ],
                            "And 2 more entries, set log level to debug to see all entries"
                        ],
                        "j5BJDZj2dA5MwmDTSYdJeSmE"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 137,
                    "function": "executeController",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args": [
                        [
                            "OCA\\Forms\\Controller\\ApiController"
                        ],
                        "insertSubmission"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/AppFramework/App.php",
                    "line": 184,
                    "function": "dispatch",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args": [
                        [
                            "OCA\\Forms\\Controller\\ApiController"
                        ],
                        "insertSubmission"
                    ]
                },
                {
                    "file": "/var/www/html/lib/private/Route/Router.php",
                    "line": 315,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::",
                    "args": [
                        "OCA\\Forms\\Controller\\ApiController",
                        "insertSubmission",
                        [
                            "OC\\AppFramework\\DependencyInjection\\DIContainer"
                        ],
                        [
                            "v2.4",
                            "ocs.forms.api.insertSubmission"
                        ]
                    ]
                },
                {
                    "file": "/var/www/html/ocs/v1.php",
                    "line": 65,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->",
                    "args": [
                        "/ocsapp/apps/forms/api/v2.4/submission/insert"
                    ]
                },
                {
                    "file": "/var/www/html/ocs/v2.php",
                    "line": 23,
                    "args": [
                        "/var/www/html/ocs/v1.php"
                    ],
                    "function": "require_once"
                }
            ],
            "File": "/var/www/html/lib/private/Files/View.php",
            "Line": 1128
        },
        "CustomMessage": "Exception thrown: Exception"
    },
    "id": "65fc7796c16d7"
}

The data is not written to the .ods-file. However, the answers arrive safely in the database and are shown in the results of the respective form.

This does not happen if the file is stored in a directory that belongs to the same user as the form does.

Nextcloud v28.0.3
Forms v4.1.1

@mcnesium Thanks for the bug report :) Just to make sure: user B has write access to the shared folder?

Yes. When testing this, I chose 'custom permissions' and ticked every checkbox available: read, write, edit, share, delete.

Ok, thank you, I'll try to reproduce it here :)

@mcnesium Another question: who fills out the form and submits it in your example?

I created a new folder with user A and shared it with full access to user B. User B created a new linked file in the shared folder. User B then filled the form and submitted it. No error shown

This is not a forms error, but comes from files_versions, I will investigate.
It seems this is already fixed upstream. The fix will be available in Nextcloud 28.0.4 next week.

nextcloud/server@3263de7