Comments

damien tournoud’s picture

I think it makes sense to reject invalid UTF-8 values when submitting a form. But I would simply do that in drupal_build_form() when we map $_GET or $_POST to $form_state['input'].

damien tournoud’s picture

StatusFileSize
new1.45 KB

Or even earlier in the process?

damien tournoud’s picture

StatusFileSize
new963 bytes

A (maybe faster) alternative.

Status: Needs review » Needs work

The last submitted patch, 943722-invalid-utf8-alternative.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB

Hm, not sure -- We'd rely on serialize()'s (unknown?) behavior with regard to invalid UTF-8 -- could also have performance implications.

Here's a variant of #2.

dries’s picture

I agree that this is needed. We often get invalid UTF-8 submitted through comment forms.

sun’s picture

StatusFileSize
new1.66 KB

Fixed the recursion logic.

smk-ka’s picture

Always reject form submissions that contain invalid UTF-8.

No, please don't do that, as it's very bad for UX. Invalid UTF-8 is always generated by machines, and you leave the user with a bunch of text (usually copy-pasted from somewhere) that they cannot use, and present them an error message. How is the user supposed to proceed? Instead, invalid UTF-8 can be easily filtered out, at least if you know a value is supposed to be plain text.

chx’s picture

I ... do not know. There is sense in this for sure. But do we really want this to be done in bootstrap when form API has recursion handling already? Also, our philosophy was no to mangle user data but to change on output only. And then there is the question -- did the whole world migrate to UTF8 solidly? Is there no need for a $conf override to opt out?

dries’s picture

For example, in the case of the Mollom module, this is what happens when a node or comment with invalid UTF-8 is submitted through Drupal:

  1. The Mollom module converts it into XML so it can be send over XML-RPC. Because of the invalid UTF-8, the resulting XML is invalid too. The backend parser throws up and returns an XML-RPC error. If the Mollom fallback mode is set to 'accept comments' when an error occurs, the spam is accepted as ham. This provides spammers an easy way to by-pass Mollom. On the flip side, it can also cause valid ham with broken UTF-8 to be rejected.
  2. If the node or comment is shown on a page with doctype XHTML, the page won't validate.
  3. If the node or comment is shown in an RSS feed, the RSS feed won't render in many feed readers.

Our options:

  1. Reject invalid UTF-8 on input. This is implemented by this patch.
  2. Turn invalid UTF-8 into valid UTF-8 on input.
  3. Turn invalid UTF-8 into valid UTF-8 on output.
chx’s picture

Note that check_plain already turns invalid UTF-8 into the empty string. I would be OK with a form based approach if there is an opt out.

effulgentsia’s picture

Presumably option #10.3 either already is or can be supported via an input format filter. Regradless of that, there seems to be use-cases for #10.1 and #10.2 and for nothing at all. And potentially someone might want to choose a different option based on the form/URL or other context information (for example, #10.1 for anonymous and #10.2 for admins).

Do we already have an early bootstrap handler we can piggy back on to? If not, can we make a new one? And let this problem be solved in contrib?

sun’s picture

@chx: Good points. The initial/original patch in #0 implemented a validation inside the usual recursion inside Form API. If we go that route, then I'd rather suggest to investigate Damien's proposal in #1; i.e., only considering a form for processing if we have valid UTF-8 input, prior to setting $form_state['input']. The reason why we quickly resorted to performing this validation in drupal_environment_initialize() is that _form_builder_handle_input_element() would still assign #value properties containing invalid UTF-8 when building a form. Therefore, we considered the patch in #0 to be insufficient.

chx’s picture

StatusFileSize
new705 bytes
  • Do we want to throw out user input just because of a single non-UTF-8 character, who knows copied from where? I will presume no.
  • Do we want to burden bootstrap with a tricky regex? No.
chx’s picture

StatusFileSize
new709 bytes

That's not quite enough. But this is. I might come up with a test, even.

Status: Needs review » Needs work

The last submitted patch, simple_little_regex.patch, failed testing.

damien tournoud’s picture

I fail to see the intend of #15 and #16, but I'm very reluctant to just remove characters from the input stream like this. It might have some nasty consequences.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new711 bytes

The goal here is to remove invalid UTF-8 sequences. The regexp captures valid UTF-8 sequences and also matches anything else but those are not captured and so they get removed.

Status: Needs review » Needs work

The last submitted patch, simple_little_regex.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new857 bytes

I agree we should limit this validation to form input handling. Attached patch uses drupal_validate_utf8(). If that is not sufficient, then drupal_validate_utf8() is bogus.

Did not add form_set_error(), but I really think that posting invalid UTF-8 should prevent a form from submitting.

sun’s picture

StatusFileSize
new878 bytes

$input needs to be a string, of course.

sun’s picture

Issue tags: +Needs tests

Pretty sure that #22 + throwing a form error is the way to go. Needs tests to confirm.

sun’s picture

#22: drupal.form-validate-utf8.22.patch queued for re-testing.

fgm’s picture

StatusFileSize
new751 bytes

Rerolled on a current 7.x.

chx’s picture

Status: Needs review » Needs work

#21 yes, yes and yes. The rest, no, you can't possibly suggest to just throw away some user input without notifying the user.

Mark_L6n’s picture

A couple of reasons to not submit a form with the portion of text that fails the UTF8 regex test excluded are:
1) If there is an error in a UTF8 string, you can't be positive of the error boundaries, as part of the erroneous sequence could by coincidence be part of a regex match.
2) A completely random byte sequence would likely contain some matches, as the categories are pretty broad.

sun’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.53 KB

Re-rolled against HEAD. Still needs tests.

Status: Needs review » Needs work

The last submitted patch, 28: drupal8.form-validate-utf8.28.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 28: drupal8.form-validate-utf8.28.patch, failed testing.

mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev
Assigned: sun » Unassigned
Issue summary: View changes
Issue tags: +Security

It seems to me that this could potentially be a security issue. It's been dormant for so long, it may not be an issue any more. Just trying to clean up assigned & inactive issues.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan’s picture

Category: Bug report » Feature request
Issue tags: +Bug Smash Initiative, +Needs steps to reproduce, +Needs issue summary update, +Needs reroll

Reviewed this as part of the bug smash initiative. Judging by the discussion and debate on this issue it seems like this is probably a feature request. Happy for it to be changed back if I've misunderstood.

Needless to say this needs a reroll, looks like \Drupal\Core\Form\FormBuilder::handleInputElement has replaced _form_builder_handle_input_element. We also need steps to reproduce and test coverage.

medha kumari’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new844 bytes

Rerolled the patch #25 in Drupal 10.1.x.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.79 KB

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.