Homec4science

Automatically escape HTML

Authored by vrana <jakubv@fb.com> on Jan 18 2013, 02:59.

Description

Automatically escape HTML

Summary:
This creates a class marking a string as safe for usage in HTML.
It automatically escapes everything else in phutil_tag().

It should simplify the code by removing all phutil_escape_html() used in phutil_tag().
It should also prevent XSS because it would be impossible to forget about escaping.
It should also prevent double escaping as phutil_escape_html(phutil_escape_html($s)) is safe.

The downside of this approach is that id(new PhutilHTML($s)).id(new PhutilHTML($s)) is a string that is not marked as HTML.
That's the reason why I've added the array semantics to $content.

I didn't measure the performance impact but if it wouldn't be horrible then I think it's worth it.

Test Plan: Loaded Phabricator homepage.

Reviewers: epriestley, btrahan

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T139

Differential Revision: https://secure.phabricator.com/D4499

Details

Committed
vrana <jakubv@fb.com>Jan 25 2013, 03:46
Pushed
aubortMar 17 2017, 12:03
Parents
rPHUbb38524f2936: Adds language support for ALLCAPS (for testing phts)
Branches
Unknown
Tags
Unknown

Event Timeline

vrana <jakubv@fb.com> committed rPHU42ac69282150: Automatically escape HTML (authored by vrana <jakubv@fb.com>).Jan 25 2013, 03:46