First class markup like JSX or XHP #5
Replies: 6 comments 19 replies
-
I'm not familiar with XHP, does the https://github.com/phplang/xhp extension cover your needs? |
Beta Was this translation helpful? Give feedback.
-
There was proposal for https://wiki.php.net/rfc/is_literal that would solve this problem in general and universal way without adding another language(html/xml) parser. |
Beta Was this translation helpful? Give feedback.
-
One advantage of a native/bundled syntax over the existing user-space solutions is the compiler can handle compilation and syntax validation, and translate it into more mundane and faster opcodes. Assuming we trust that code, anyway. |
Beta Was this translation helpful? Give feedback.
-
In your first example, you have:
Note the lack of quote marks aground the variable. Are the variables simply passed though If so, should the author be required to quote the attribute? or would PHP add the quotes marks automatically (single or double)? or would PHP need to do HTML attribute based escaping (e.g. spaces to
And what happens with:
And what happens with:
And these are the basic ones, wait until you start looking at what happens with complex parsing... e.g. CSS, Mutation XSS, the complexities of SVG and MathML (see mglyph and malignmark). Also, what happens if $_POST['username'] is not defined? As that's kinda NULL, and PHP 8.1 deprecated NULL being passed to functions like |
Beta Was this translation helpful? Give feedback.
-
One thing that has come up is how we could go beyond preventing XSS into actually managing the types and sources of content that are allowed and one thought I had that I'd like to get out is that content security policies exist for this very reason. $policy = \PhpMl\Csp::()->sources(default: 'self', script: 'https://somesite.com')->throwOnFailure();
$policy = \PhpMl\Csp::()->sources(default: 'self')->removeOnFailure();
// Globally
\PhpMl\PhpMl::setGlobalPolicy($policy);
// With a specific block
$myLink = 'javascript:doSomething()';
$content = <a href={$myLink}></a>
// Echo with global policy
echo $content; // <a></a>
// Echo rendered with specific policy
echo $content->renderWithPolicy($policy->allowUnsafeInline()); // <a href='javascript:doSomething()'> This does increase the potential barrier for entry a bit, but I think this could also be a great thing for a web language to have. |
Beta Was this translation helpful? Give feedback.
-
Just a side-note: latte templating system has strong context-aware escaping functionalities. Not an ad, just to be aware of various user-land solutions :) |
Beta Was this translation helpful? Give feedback.
-
For a language that by-and-large supports the web, PHP has pretty limited support for markup and proper sanitization. It'd be amazing if PHP had support for XHP style markup and provided context-specific sanitized output by default:
Outputting without sanitization could use syntax or a type to manage:
<div>{{$html}}</div>
<div>{Element::unsafe($html)}
I believe having support for this sort of thing in PHP would lead to a huge reduction in XSS vulnerabilities introduced.
Beta Was this translation helpful? Give feedback.
All reactions