Problem/Motivation

When a webform has a managed_file element, which is set to be encrypted, only the value of the field is encrypted, but not the file itself. I think it's a fair assumption that this is not the expected behaviour.

The severity of this is mitigated for three reasons:

  1. Anonymous files can only be uploaded to private.
  2. The links to the files are only displayed if the user can see encrypted webform values.
  3. If someone tries to directly access the file by using a direct url, the user is required to have permission to view the webform submission.

Still, if someone could somehow figure out the internal path to the file, and had access to private files, they would see the unencrypted file.

Discovered while trying to reproduce #3035804: Access encrypted file uploaded by anonymous user

Proposed resolution

Figure out if we can actually encrypt the file's content before saving to disk.

Remaining tasks

  • Fix it.
  • Add test coverage.

User interface changes

None.

API changes

None?

Data model changes

None

Comments

Manuel Garcia created an issue. See original summary.

manuel garcia’s picture

StatusFileSize
new5.52 KB

Moving here the patch on #3035804: Access encrypted file uploaded by anonymous user which verifies access to files uploaded to webform.

Note that this not yet includes coverage for the reported bug, but I feel we can iterate on it here.

manuel garcia’s picture

Issue summary: View changes
manuel garcia’s picture

StatusFileSize
new35.6 KB

Also noticing that instead of showing [Value Encrypted], it is showing Test File {Empty}

manuel garcia’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.84 KB
new6.02 KB

Here is coverage for the bug itself, which should fail.

Discovered another mitigation factor I've found while writing the test: the user directly accessing the uploaded file must have access to view the webform submission.

manuel garcia’s picture

StatusFileSize
new3.89 KB
new6.16 KB

OK I had to make some changes to the test to get this going, using an asset text file to simplify things and making sure to remove the new line from the string returned by file_get_contents.

Also added an assertion to verify that when the user has the 'view encrypted values' he can actually see the original content of the file.

It should hopefully come back red, verifying the reported bug.

Status: Needs review » Needs work

The last submitted patch, 6: 3038902-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

JvE’s picture

As a workaround we've installed the file_encrypt module and created a "webform" encryption profile.
This allows you to choose the 'encrypt' filesystem when configuring file upload elements in a webform.

manuel garcia’s picture

Thank you @JvE for sharing your workaround here. I believe that is probably the best approach to doing this right now, and perhaps webform_encrypt should not be responsible for encrypting the files themselves and outsource that to file_encrypt module.

I believe the best we could do without adding too much complexity here would be to warn the user if they configure a webform field with files to be encrypted to also use file_encrypt module. Or just document it in the README / Project page?

malcomio’s picture

Using file_encrypt seems to work for us, although we have found #3123160: Incorrect URLs for files uploaded via webform with file_encrypt .

robcarr’s picture

Six years on and File Encrypt still the only way to solve this. It works.

The solution in this module (Webform Encrypt) apparently only encrypts the filename in the database