-
Notifications
You must be signed in to change notification settings - Fork 87
Prevent AbstractHelper from attempting to output malformed user input #193
Conversation
…likely crafted) input is received. Test added to demonstrate how a simple invalid 2 octet sequence can cause an exception (which then causes your server to 500).
I can confirm this problem! And also the existence in zend-view: echo $this->htmlList($items, null, ['id' => "\xc3\x28"]); Throws the same exception:
|
I had debated pitching a fix for Zend Escaper -- but it seems the intent there was to actually detect and report failure which could be valid in some cases. The sprintf on bad utf8 is a strange decision, but if we agree we should retain it (and should probably never use its error message!), then this type of band-aid I felt was the next best idea in any component that uses it. |
@Saeven zend-escaper is supposed to sanitize strings for the purposes of display. If As such, I think the fix belongs in zend-escaper, and then we can update zend-form to pin to the version where such a fix is introduced. Would you be willing to create the pull request there? |
Yep my pleasure, didn't know if we should protect the original behavior. I'll submit a lower-level patch in this case. |
As per discussion with @Saeven on slack, this issue is not in the This prevents the influx of invalid information into the system in first place (common issue), while adding filtering to the |
src/View/Helper/AbstractHelper.php
Outdated
$escapedAttribute = $escapeAttr($value); | ||
$strings[] = sprintf('%s="%s"', $escape($key), $escapedAttribute ); | ||
} | ||
catch( \Zend\Escaper\Exception\RuntimeException $x ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this fix kinda makes sense here, although what we should do is preventing influx of invalid data overall.
Once it is in the system (any system) then the escaper will make apps crash (expected), but that's the least of the concerns with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same feeling initially, to preserve Zend Escaper's behavior.
Should the populateValues entry point be considered instead?
https://github.com/zendframework/zend-form/blob/master/src/Form.php#L938
Thanks for the Slack chat this morning @weierophinney and @Ocramius. Had to jump off to get internal work done, but I would like to help. Testing Occam's Razor, this approach solves the case for my immediate problem (on Zend Form). Also tested with Acunetix's latest version; I could continue to write real tests for nested circumstances if the approach is deemed sound:
It removes malformed utf8 from any part of the form's payload and has a very negligible impact. Probably preempts any BCs? Should the solution be more pointed? Cheers. |
Would you be open to a PR that pushes filtered values into the element set to prevent this kind of issue? In other words, if a filter is installed, no unfiltered values should ever persist within the object (post-filter). As a developer, the covenant becomes that filters, if configured, gain god-status. |
Prevent AbstractHelper from attempting to output malformed user input
Thanks, @Saeven. |
Before this PR, malformed UTF8 submitted to a Zend Form causes the form helper to throw a 500 post-submission. This PR and its test eliminates these errors, by silently removing attack input during the print cycle.
Test added to demonstrate how a simple invalid 2 octet sequence can cause an exception (which then causes your server to 500).
Note that under current behavior, the helper will still throw the error despite all Filter and Validator implementations. A full test case that demonstrates this is available here: https://github.com/Saeven/zendframework-form-failure
A change is necessary to prevent routine penetration tests, or user-land attacks from causing critical exceptions. Users shouldn't be able to craft malicious input that causes 500s.
Thank you for considering this PR.