-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
Can we add an option to disabled SafeClass ? #211
Comments
Just here is an example of a situation where by deactivating the basic behavior I could make the code more readable. <div
class={
"absolute inset-x-0 bottom-0 flex items-center justify-between gap-2 p-6 py-4",
templ.KV("flex-row-reverse", variant != "A"),
templ.SafeClass("app-hero-slide-move translate-y-full opacity-0 transition duration-[750ms] ease-out"),
}
> |
I think I'd really like a option like this. What am building right now I can't ever imagine why I'd pass user input into the CSS classes. I'm also struggling to imagine a scenario where this could be possibly really dangerous for my application. I think there's valid concerns with scripts and urls. But I'm not sure about CSS classes? |
https://html.spec.whatwg.org/#classes There's no rules in HTML on what a class can or can't be. Should we deprecate class: |
Even google/safehtml doesn't sanitize classs names: https://github.com/google/safehtml/blob/be23134998433fcf0135dda53593fc8f8bf4df7c/template/sanitizers.go#L257 |
Personally I agree to keep banning quote cause of course If you can inject in a Class and break the attribute, this could lead to XSS. But I don't see why permit space would also lead to XSS ? |
Sorry, I worded that badly! We definitely should allow spaces in the class attribute as that's how you split class names. I don't believe there's a security risk to spaces. |
But I believe class names are still somehow escaped to prevent See
Apparently the class name is already escaped in templ: I would also be in favor of dropping the |
Ok I just found using |
I checked against the behaviour of other sytems, such as React, and found that CSS class names were not sanitized, even if the CSS class names come from strings which are not under the developer's control. As per @oliverpool's comment in #211 (comment) templ already HTML attribute encodes all class name values, so we think that this is enough. To prevent breaking existing code, the SafeCSS and other functions will need to remain. It could be that we can deprecate those functions. What do people think about the PR. As per expectations? |
LGTM, maybe we add some godoc deprecations for the unneeded bits of the runtime? That way people's static check tools can let them know they can remove some code. |
@a-h Just thank you! I know it's unusual to thank someone in a closed ticket several days after but with the removal of 66 |
It's really nice of you to spend your time to do that. Thanks! |
The idea of not trusting user input by default is a good one.
Especially on suspicious character.
But for me I use a lot of TailwindCSS and the need to wrap nearly every class with
SafeClass
is overwhelm.I don't want to change the default behavior of Templ.
No I prefer to propose to add an option to disable this behaviour so code using a lot of utility function with special character can be easy and quick to write.
And also with this option we can Imagine add an
EscapeClass
function to enable back the escape on specific part of our code.Oh and when I say "an option", I mean in the
templ generate
command.If necessary I will obviously see how to implement this but first I would like to know if this is something that is of interest or not.
The text was updated successfully, but these errors were encountered: