I'm not 100% sure that this is a bug, but I wanted to report it in case other people ran across this issue...

Problem/Motivation

We've got a webform to collect job applications:

1. This webform includes a private file attachment field for the resume.
2. Anonymous users are allowed to create submissions.
3. The file attachment field has "Element access" settings to allow only administrative users to "View webform submission".
4. There is a handler set up to send an email with the submission values ([webform_submission:values]) to administrative users.
5. The email should include a link to the private file.

If the form is submitted by an administrative user, the link to the private file *is* included. If it's submitted by an anonymous user, the link to the private file *is not* included.

This is because of a call to WebformElementBase::checkAccessRules() by WebformSubmissionViewBuilder::buildElements(). $element['#access_view_roles'] is set for the file field, and administrative users are allowed while anonymous users are not.

Proposed resolution

To work around / solve this, we changed the "Element access" settings mentioned above to allow both anonymous and authenticated users to "View webform submission". Leaving this setting blank did not work. Making this change was acceptable because we had other access restrictions set to prevent anonymous users from viewing submissions at all.

Questions

Because of item 3 above, this *may* be the expected behavior. Is this the case? If so, it's a bit confusing that the "Element access" would carry over to the contents of the email and would then be dependent on the user filling out and submitting the form. It doesn't seem like the email should be different based on the permissions of the submitter.

Should the email be allowed to just include everything, regardless of permissions? Then, the site builder would be responsible for sending the right content to the right recipients. Actual access to any link would end up being controlled by the site once the recipient clicked on it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrb created an issue. See original summary.

jrockowitz’s picture

Should the email be allowed to just include everything, regardless of permissions?

YES!!! This will require some work and test coverage.

I think we might have to include a link to the private file that redirects to the user login page if the user can't access private webform file upload.

  • jrockowitz committed 38035e5 on 2885507-email-element-access
    Issue #2885507: Email sent via handler can'\''t include link to private...

  • jrockowitz committed a67bd58 on 2885507-email-element-access
    Issue #2885507: Email sent via handler can't include link to private...
jrockowitz’s picture

Status: Active » Needs review
FileSize
36.77 KB

Status: Needs review » Needs work

The last submitted patch, 5: email_sent_via_handler-2885507-4.patch, failed testing. View results

jrockowitz’s picture

You will now have to explicitly decide if access controls should be ignored.

This is tricky because the absolute last thing we want to happen is accidently including private elements in emails generated by anonymous users.

  • jrockowitz committed 7dcfc5c on 2885507-email-element-access
    Issue #2885507: Email sent via handler can't include link to private...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
37.39 KB

  • jrockowitz committed 3aa6b48 on 2885507-email-element-access
    Issue #2885507: Email sent via handler can't include link to private...

  • jrockowitz committed 5841bde on 8.x-5.x
    Issue #2885507 by jrockowitz: Email sent via handler can't include link...
jrockowitz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.