Needs work
Project:
Drupal core
Version:
main
Component:
forms system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
16 Oct 2010 at 20:28 UTC
Updated:
30 Jan 2023 at 23:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
damien tournoud commentedI 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'].
Comment #2
damien tournoud commentedOr even earlier in the process?
Comment #3
damien tournoud commentedA (maybe faster) alternative.
Comment #5
sunHm, 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.
Comment #6
dries commentedI agree that this is needed. We often get invalid UTF-8 submitted through comment forms.
Comment #7
sunFixed the recursion logic.
Comment #8
smk-ka commentedNo, 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.
Comment #9
chx commentedI ... 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?
Comment #10
dries commentedFor 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:
Our options:
Comment #11
chx commentedNote 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.
Comment #12
effulgentsia commentedPresumably 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?
Comment #13
sun@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.
Comment #14
chx commentedComment #15
chx commentedThat's not quite enough. But this is. I might come up with a test, even.
Comment #17
damien tournoud commentedI 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.
Comment #19
chx commentedThe 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.
Comment #21
sunI 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.
Comment #22
sun$input needs to be a string, of course.
Comment #23
sunPretty sure that #22 + throwing a form error is the way to go. Needs tests to confirm.
Comment #24
sun#22: drupal.form-validate-utf8.22.patch queued for re-testing.
Comment #25
fgmRerolled on a current 7.x.
Comment #26
chx commented#21 yes, yes and yes. The rest, no, you can't possibly suggest to just throw away some user input without notifying the user.
Comment #27
Mark_L6n commentedA 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.
Comment #28
sunRe-rolled against HEAD. Still needs tests.
Comment #33
mgiffordIt 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.
Comment #48
mstrelan commentedReviewed 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::handleInputElementhas replaced_form_builder_handle_input_element. We also need steps to reproduce and test coverage.Comment #49
medha kumariRerolled the patch #25 in Drupal 10.1.x.
Comment #50
needs-review-queue-bot commentedThe 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.