Replies: 2 comments 2 replies
-
|
This is an incredible use-case. 😅 I’ve considered supporting unsafe attributes with a special type that bypasses the safety checks. The interface would be something like this. a href: safe("javascript:alert(1)")For your use case, I wonder if you could just unescape the final output with You could do this for specific blocks of content by defining a method like this. def safe_output(&block)
unsafe_raw(
CGI.unescape_html(
capture(&block)
)
)
endThen just use it like this safe_output do
a href: "<?= path_for('/home') ?>"
endYou'll probably need to |
Beta Was this translation helpful? Give feedback.
-
|
We also want to take risks sometimes. 😅 Especially helpful during the transition from JS frontend to Phlex. fancy_button(onclick: 'alert("Hello World!")') { 'Click me' } |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I think I have a fringe use-case where
unsafe_rawand unescaped attributes might be necessary.I'm using Phlex to render navbars dynamically and dump them to a PHP file for some old PHP websites.
I need
unsafe_rawto be able to dump PHP blocks:(I know this is terrible, it's not a good architecture, this is not how/where this function should be defined etc, but it's something I have to deal with, so bear with me please)
site_directoryis not user provided.Now I need to use that PHP function in
a(href)attributes, the output needs to look like:but of course right now the attribute value would be escaped and not work.
One way I could make this work is by patching
__build_attributes__to not escape the attribute value if it's marked as safe, I'm using rails'html_safefor this:Note that I escaped the user-provided dangerous bit (
item.link) before marking the string as safe.I hate this, of course. Maybe there's a better way to do it?
Beta Was this translation helpful? Give feedback.
All reactions