Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create types for avoiding escaping #77

Open
FCO opened this issue Jul 26, 2022 · 5 comments
Open

Create types for avoiding escaping #77

FCO opened this issue Jul 26, 2022 · 5 comments

Comments

@FCO
Copy link

FCO commented Jul 26, 2022

It would be very helpful if there were 2 types (maybe 2 roles) that when a template tag recipe an instance of that type,
it would automatically avoiding escaping it. Maybe it could be something like HSML and JAVASCRIPT roles and that would
automatically apply &HTML and &HTML-AND_JAVASCRIPT (maybe a &JAVASCRIPT if that exists), so when doing:

<.method-returning-html>

and the object on $_ has something like:

method method-returning-html {
   '<a href="http://pudim.com.br">Pudim</a>' does HTML
}

it would behave as it were:

<&HTML(.method-returning-html)>

and also existing:

class Link {
   has Str $.title;
   has Str $.href;

   method Str {
      qq'<a href="$!href">$!title</a>' does HTML
   }
}

if we have:

<.pudim-link>

and that returns something like:

method pudim-link { Link.new: :title<Pudim>, :href<http://pudim.com.br> }

it would be equivalent to:

<&HTML(.pudim-link.Str)>

and the same for JS

@vendethiel
Copy link
Member

If anything, I feel like this should be fragments, because that's prone to XSS and it doesn't need to be. Strings should be avoided where possible.

@FCO
Copy link
Author

FCO commented Jul 26, 2022

@vendethiel sorry, what do you mean by fragments?

@FCO
Copy link
Author

FCO commented Jul 26, 2022

But using those types, wouldn't that mean you KNOW that's HTML or JS?! you WANT that to not be escaped? The same as using &HTML and &HTML-AND-JAVASCRIPT

@vendethiel
Copy link
Member

I mean that, in your example, $!href and $!title are prone to injection, because you trusted the whole thing.
If you had to build it manually, as in: raw('<a href="', ), $!link, raw('">'), $!title, raw('</a>') for example (or, for everyone who wrote CGI scripts a few decades ago, a($!title, href => $!title))) then this'd leave a lot less room for error

@FCO
Copy link
Author

FCO commented Jul 26, 2022

My suggestion was more on a automated way of making a return not being escaped then how to make that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants