Quantcast

Grails 2.0: Change default-codec to ‘html’ ?

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Grails 2.0: Change default-codec to ‘html’ ?

mos-7
Hello,

I would suggest a small change which makes many of the the (new)
Grails Projects out there much more safe:

grails.views.default.codec = "html"
should be the default if new projects are generated.

I saw so many projects in my Grails consulting that didn’t change this (because they did not know or just forgot it). To change this afterwards is a pain and leads to increased effort.

For 99% of all Grails applications there shouldn't be a problem with a default codec of "html".
Please check:
http://www.mosbase.com/2011/08/grails-security-xss-prevention-using.html

Cheers,
Mos
---
http://www.mosbase.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

smaldini
I agree it would be important to make this move, like Rails 3. We still have <%= %> for raw unencoded things but I don't find it very cool looking syntax, perhaps something like ${raw expr} would be better.

On Mon, Aug 1, 2011 at 11:18 AM, Mos <[hidden email]> wrote:
Hello,

I would suggest a small change which makes many of the the (new)
Grails Projects out there much more safe:

grails.views.default.codec = "html"
should be the default if new projects are generated.

I saw so many projects in my Grails consulting that didn’t change this (because they did not know or just forgot it). To change this afterwards is a pain and leads to increased effort.

For 99% of all Grails applications there shouldn't be a problem with a default codec of "html".
Please check:
http://www.mosbase.com/2011/08/grails-security-xss-prevention-using.html

Cheers,
Mos
---
http://www.mosbase.com/



--
Stéphane MALDINI
--


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

Marc Palmer Local

On 1 Aug 2011, at 10:25, Stephane Maldini wrote:

> I agree it would be important to make this move, like Rails 3. We still have <%= %> for raw unencoded things but I don't find it very cool looking syntax, perhaps something like ${raw expr} would be better.
>
> On Mon, Aug 1, 2011 at 11:18 AM, Mos <[hidden email]> wrote:
> Hello,
>
> I would suggest a small change which makes many of the the (new)
> Grails Projects out there much more safe:
>
> grails.views.default.codec = "html"
> should be the default if new projects are generated.
>
> I saw so many projects in my Grails consulting that didn’t change this (because they did not know or just forgot it). To change this afterwards is a pain and leads to increased effort.
>
> For 99% of all Grails applications there shouldn't be a problem with a default codec of "html".
> Please check:
> http://www.mosbase.com/2011/08/grails-security-xss-prevention-using.html 

Hi all,

I agree that we need to be safer out of the box, but in my experience the default codec (as it stands) is not the solution.

There needs to be a more detailed review of the problem because as Stéphane said, its too easy to bypass default codec - and we've seen people use <%= specifically for that case.

The other reason is that default codec is a complete anti-pattern for plugins. Having the app able to change the default codec at will means that all plugins have to assume nothing about default codec and ALWAYS override default codec themselves in every GSP.

This is pretty lame.

Marc
~ ~ ~
Marc Palmer
Freelancer (Grails/Groovy/Java)

Founder @ http://noticelocal.com | Developer @ http://weceem.org
Member @ http://spottymushroom.com | Contributor @ http://grails.org
Twitter: http://twitter.com/wangjammer5 | Resumé: http://www.anyware.co.uk/marc/
Blog: http://www.anyware.co.uk | Grails Rocks: http://www.grailsrocks.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
> There needs to be a more detailed review of the problem because as Stéphane said, its too easy to bypass default codec - and we've seen people use <%= specifically for that case.

I don't see a problem with <%= %>.  It's ok to use it in the exceptional cases if no html-encoding should be applied (check my blogpost). Other way around:  Having a feature like <%= => is a requirement to make the default-html-codec flawless.

>The other reason is that default codec is a complete anti-pattern for plugins. Having the app able to change the default codec at will means that all plugins have to assume nothing about default codec and ALWAYS override default codec themselves in every GSP.

That has nothing to do with my suggestion to change the default in Grails 2.0. 
And indeed I think a plugin should not(!) assume anything about the defaullt codec of the application.
In general a plugin should work regardless of the default codec.
Only in special cases,  e.g. html-ouput or plain-text for emails, a plugin should override the codec themselve in the GSPs.

Cheers,
Mos
---
http://www.mosbase.com/


On Mon, Aug 1, 2011 at 11:51 AM, Marc Palmer <[hidden email]> wrote:

On 1 Aug 2011, at 10:25, Stephane Maldini wrote:

> I agree it would be important to make this move, like Rails 3. We still have <%= %> for raw unencoded things but I don't find it very cool looking syntax, perhaps something like ${raw expr} would be better.
>
> On Mon, Aug 1, 2011 at 11:18 AM, Mos <[hidden email]> wrote:
> Hello,
>
> I would suggest a small change which makes many of the the (new)
> Grails Projects out there much more safe:
>
> grails.views.default.codec = "html"
> should be the default if new projects are generated.
>
> I saw so many projects in my Grails consulting that didn’t change this (because they did not know or just forgot it). To change this afterwards is a pain and leads to increased effort.
>
> For 99% of all Grails applications there shouldn't be a problem with a default codec of "html".
> Please check:
> http://www.mosbase.com/2011/08/grails-security-xss-prevention-using.html

Hi all,

I agree that we need to be safer out of the box, but in my experience the default codec (as it stands) is not the solution.

There needs to be a more detailed review of the problem because as Stéphane said, its too easy to bypass default codec - and we've seen people use <%= specifically for that case.

The other reason is that default codec is a complete anti-pattern for plugins. Having the app able to change the default codec at will means that all plugins have to assume nothing about default codec and ALWAYS override default codec themselves in every GSP.

This is pretty lame.

Marc
~ ~ ~
Marc Palmer
Freelancer (Grails/Groovy/Java)

Founder @ http://noticelocal.com | Developer @ http://weceem.org
Member @ http://spottymushroom.com | Contributor @ http://grails.org
Twitter: http://twitter.com/wangjammer5 | Resumé: http://www.anyware.co.uk/marc/
Blog: http://www.anyware.co.uk | Grails Rocks: http://www.grailsrocks.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

Marc Palmer Local

On 1 Aug 2011, at 11:08, Mos wrote:

> > There needs to be a more detailed review of the problem because as Stéphane said, its too easy to bypass default codec - and we've seen people use <%= specifically for that case.
>
> I don't see a problem with <%= %>.  It's ok to use it in the exceptional cases if no html-encoding should be applied (check my blogpost). Other way around:  Having a feature like <%= => is a requirement to make the default-html-codec flawless.
>
> >The other reason is that default codec is a complete anti-pattern for plugins. Having the app able to change the default codec at will means that all plugins have to assume nothing about default codec and ALWAYS override default codec themselves in every GSP.
>
> That has nothing to do with my suggestion to change the default in Grails 2.0.  
> And indeed I think a plugin should not(!) assume anything about the defaullt codec of the application.
> In general a plugin should work regardless of the default codec.
> Only in special cases,  e.g. html-ouput or plain-text for emails, a plugin should override the codec themselve in the GSPs.
>

Yeah, but what I mean is, that there is a wider issue to be discussed / established here. It's worth having a full discussion about this because - who knows - default codec as a concept may not be needed after all.

For example with plugins, you have to set default codec to html or none explicitly in every GSP anyway - and fact is most plugins don't (I know none of mine do). So there is a big legacy issue here.

Setting default codec to html on new projects will break an awful lot of plugins for people out of the box. This doesn't mean it is not a valid approach, but it has a high cost associated currently.

We've had a lot of discussions about this, and evolved thinking, forgotten, and re-remembered and forgotten again :)

The core problem is that the GSP author (unless they are also the app author, which is not always the case) has no clue what codec will be applied to an EL value, unless they put a directive at the top of their page. This will lead to defensive programming and negate the entire value of default codecs because every GSP will do a "codec reset". (think CSS reset)

The codec in force needs to have some visibility, and it needs to be possible to switch mid-page.

I think my most recent plan/idea in this regard was:

* Add "encodeAs" or "codec" attribute to the GSP tag mechanism, so it is automatically applied to any and all tags with no effort from the tag author.  We already have encodeAs support on a few tags, but it is explicitly added. Example:
<script …>
    var url = "${g.createLink(controller:'book', encodeAs:'JavaScript')";
</script>

* Add an "encode" tag namespace for blocks of content:

<encode:html>
This is where I put all my unsafe ${userName} and ${email} stuff,
but what happens when we include a template or other tag content with g:render/include?
Surely all should be escaped.
</encode:html>

* Add a way for the default ("current") codec to be changed temporarily, e.g. inside the implementation of another tag:

<r:script>
    var url = "${g.createLink(controller:'book')";
</r:script>

When you're in a tag that explicitly renders a specific type of content e.g. JavaScript from g:javascript/r:script there is zero point in the user specifying the codec to use - it should be automatic. So e.g. the r:script implementation should be able to pass a codec name to the body() invoke method and all the EL evaluations within that body block are encoded with that codec by default. So basically each tag body would have a default codec passed into it, or default to codec of the outer body if there is one.


Hopefully this makes some sense…


~ ~ ~
Marc Palmer
Freelancer (Grails/Groovy/Java)

Founder @ http://noticelocal.com | Developer @ http://weceem.org
Member @ http://spottymushroom.com | Contributor @ http://grails.org
Twitter: http://twitter.com/wangjammer5 | Resumé: http://www.anyware.co.uk/marc/
Blog: http://www.anyware.co.uk | Grails Rocks: http://www.grailsrocks.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

pledbrook
> Setting default codec to html on new projects will break an awful lot of plugins for people out of the box. This doesn't mean it is not a valid approach, but it has a high cost associated currently.

Grails 2.0 gives us an opportunity to introduce this change and get
plugin authors updating their GSP pages to use the defaultEncoding
page directive. It's not a perfect solution, but I think making pages
safer by default is worthwhile. And most existing applications will
have the default encoding as "none", so it wouldn't be a breaking
change for existing apps.

> We've had a lot of discussions about this, and evolved thinking, forgotten, and re-remembered and forgotten again :)

Indeed.

> * Add "encodeAs" or "codec" attribute to the GSP tag mechanism, so it is automatically applied to any and all tags with no effort from the tag author.  We already have encodeAs support on a few tags, but it is explicitly added. Example:
> <script …>
>    var url = "${g.createLink(controller:'book', encodeAs:'JavaScript')";
> </script>

The question is whether this should be 'additive'. In other words, the
URL should probably be URL encoded and then encoded as JavaScript.
That's additive. But perhaps there are examples where you want to
override the default encoding of a tag?

Anyway, I don't think we're that far away from a solution, but I can't
see all the above being introduced for Grails 2.0. So I still think
changing the default and encouraging plugin developers to update their
plugins is the best thing to do right now.

Peter

PS What's the best channel for communicating such changes to plugin
authors? Dev mailing list with a [FAO: Plugin authors]? Something
else?

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

Nick Vaidyanathan
It seems the best way to give plugin developers feedback is to give that feedback when they try to upload the plugin/add it to the directory.

Is there a way to write an AST transform or section into the ReleasePlugin script that validates such things?  

The section could analyze GSPs and see if the codec was specified, or scan through the config file and see if the property is set. If not, reject the contribution with an error message.

This may seem a bit draconian, but is a great way to establish a precedent that "there are certain things a plugin should do before it's ready to go primetime and be consumed by the community." It's not a "cost" or "content" barrier like the Apple Store, but a code quality barrier that says "are certain default values that should be set actually good to go?" 

...of course, later I would propose expanding this to do a grails test-app and make sure the plugin has some non-trivial tests that pass before acceptance, but that would probably draw ire. Though I would argue that if we're saying "professional code/applications should have tests" and then accepting contributions with nothing but a whole bunch of void testSomething() {}, ehhhh... 

On Mon, Aug 8, 2011 at 5:30 AM, Peter Ledbrook <[hidden email]> wrote:
> Setting default codec to html on new projects will break an awful lot of plugins for people out of the box. This doesn't mean it is not a valid approach, but it has a high cost associated currently.

Grails 2.0 gives us an opportunity to introduce this change and get
plugin authors updating their GSP pages to use the defaultEncoding
page directive. It's not a perfect solution, but I think making pages
safer by default is worthwhile. And most existing applications will
have the default encoding as "none", so it wouldn't be a breaking
change for existing apps.

> We've had a lot of discussions about this, and evolved thinking, forgotten, and re-remembered and forgotten again :)

Indeed.

> * Add "encodeAs" or "codec" attribute to the GSP tag mechanism, so it is automatically applied to any and all tags with no effort from the tag author.  We already have encodeAs support on a few tags, but it is explicitly added. Example:
> <script …>
>    var url = "${g.createLink(controller:'book', encodeAs:'JavaScript')";
> </script>

The question is whether this should be 'additive'. In other words, the
URL should probably be URL encoded and then encoded as JavaScript.
That's additive. But perhaps there are examples where you want to
override the default encoding of a tag?

Anyway, I don't think we're that far away from a solution, but I can't
see all the above being introduced for Grails 2.0. So I still think
changing the default and encouraging plugin developers to update their
plugins is the best thing to do right now.

Peter

PS What's the best channel for communicating such changes to plugin
authors? Dev mailing list with a [FAO: Plugin authors]? Something
else?

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
In reply to this post by pledbrook
>So I still think changing the default and encouraging plugin developers to update their plugins is the best thing to do right now.

+1, to change the default in the upcoming Grails 2.0 M2.

I don't understand the problem with existing plugins. I think most plugins don't have to change anything.
Even today they work regardless of the default encoding.  Some applications use 'none' today, others change
it to 'html', and all of them using the same plugins today.

Cheers,
Mos
---
http://www.mosbase.com/


On Mon, Aug 8, 2011 at 2:30 PM, Peter Ledbrook <[hidden email]> wrote:
> Setting default codec to html on new projects will break an awful lot of plugins for people out of the box. This doesn't mean it is not a valid approach, but it has a high cost associated currently.

Grails 2.0 gives us an opportunity to introduce this change and get
plugin authors updating their GSP pages to use the defaultEncoding
page directive. It's not a perfect solution, but I think making pages
safer by default is worthwhile. And most existing applications will
have the default encoding as "none", so it wouldn't be a breaking
change for existing apps.

> We've had a lot of discussions about this, and evolved thinking, forgotten, and re-remembered and forgotten again :)

Indeed.

> * Add "encodeAs" or "codec" attribute to the GSP tag mechanism, so it is automatically applied to any and all tags with no effort from the tag author.  We already have encodeAs support on a few tags, but it is explicitly added. Example:
> <script …>
>    var url = "${g.createLink(controller:'book', encodeAs:'JavaScript')";
> </script>

The question is whether this should be 'additive'. In other words, the
URL should probably be URL encoded and then encoded as JavaScript.
That's additive. But perhaps there are examples where you want to
override the default encoding of a tag?

Anyway, I don't think we're that far away from a solution, but I can't
see all the above being introduced for Grails 2.0. So I still think
changing the default and encouraging plugin developers to update their
plugins is the best thing to do right now.

Peter

PS What's the best channel for communicating such changes to plugin
authors? Dev mailing list with a [FAO: Plugin authors]? Something
else?

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

pledbrook
> +1, to change the default in the upcoming Grails 2.0 M2.
>
> I don't understand the problem with existing plugins. I think most plugins
> don't have to change anything.
> Even today they work regardless of the default encoding.  Some applications
> use 'none' today, others change
> it to 'html', and all of them using the same plugins today.

If a plugin provides GSPs with explicit calls to encodeAsHTML(), those
pages will have double-encoded content. That's a significant problem.
How many plugins would be affected? Don't know. But it would be
another source of user frustration.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

pledbrook
In reply to this post by Nick Vaidyanathan
> It seems the best way to give plugin developers feedback is to give that
> feedback when they try to upload the plugin/add it to the directory.
> Is there a way to write an AST transform or section into the ReleasePlugin
> script that validates such things?

This is a great idea. So I raised an issue:

    http://jira.grails.org/browse/GPRELEASE-14

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
In reply to this post by pledbrook
> If a plugin provides GSPs with explicit calls to encodeAsHTML(), those
> pages will have double-encoded content. That's a significant problem.
> How many plugins would be affected? Don't know. But it would be
> another source of user frustration

Right, but that's the same situation as today with Grails 1.x. Isn't it?
People that switch the default to 'html' would also have double-encoded content, today.
(And I assume and hope that many people use the 'html'-default even today)

I think not many plugins use encodeAsHTML() today (and if I would consider this
as a bug, because a plugin never knows what the default encoding of the application would be).
Shouldn't we double-check if encodeAsHTML() is used in any plugins today, before discussing a theoretically problem?

Regarding encodeAsHTML() in general I would suggest a "default-checking":  Couldn't the method
just check the default and if it is set to 'html' don't encode a second time?

Cheers,
Mos
---
http://www.mosbase.com/


On Fri, Aug 12, 2011 at 4:20 PM, Peter Ledbrook <[hidden email]> wrote:
> +1, to change the default in the upcoming Grails 2.0 M2.
>
> I don't understand the problem with existing plugins. I think most plugins
> don't have to change anything.
> Even today they work regardless of the default encoding.  Some applications
> use 'none' today, others change
> it to 'html', and all of them using the same plugins today.

If a plugin provides GSPs with explicit calls to encodeAsHTML(), those
pages will have double-encoded content. That's a significant problem.
How many plugins would be affected? Don't know. But it would be
another source of user frustration.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
> Regarding encodeAsHTML() in general I would suggest a "default-checking":  Couldn't the method
> just check the default and if it is set to 'html' don't encode a second time?

Addition:  This should only apply if encodeAsHTML() is used in GSPs ${...} expressions.
  I don't know if this method could check for this context?

Cheers,
Mos
---
http://www.mosbase.com/


On Sat, Aug 13, 2011 at 2:15 PM, Mos <[hidden email]> wrote:
> If a plugin provides GSPs with explicit calls to encodeAsHTML(), those
> pages will have double-encoded content. That's a significant problem.
> How many plugins would be affected? Don't know. But it would be
> another source of user frustration

Right, but that's the same situation as today with Grails 1.x. Isn't it?
People that switch the default to 'html' would also have double-encoded content, today.
(And I assume and hope that many people use the 'html'-default even today)

I think not many plugins use encodeAsHTML() today (and if I would consider this
as a bug, because a plugin never knows what the default encoding of the application would be).
Shouldn't we double-check if encodeAsHTML() is used in any plugins today, before discussing a theoretically problem?

Regarding encodeAsHTML() in general I would suggest a "default-checking":  Couldn't the method
just check the default and if it is set to 'html' don't encode a second time?
On Fri, Aug 12, 2011 at 4:20 PM, Peter Ledbrook <[hidden email]> wrote:
> +1, to change the default in the upcoming Grails 2.0 M2.
>
> I don't understand the problem with existing plugins. I think most plugins
> don't have to change anything.
> Even today they work regardless of the default encoding.  Some applications
> use 'none' today, others change
> it to 'html', and all of them using the same plugins today.

If a plugin provides GSPs with explicit calls to encodeAsHTML(), those
pages will have double-encoded content. That's a significant problem.
How many plugins would be affected? Don't know. But it would be
another source of user frustration.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

pledbrook
>> Regarding encodeAsHTML() in general I would suggest a "default-checking":
>> Couldn't the method
>> just check the default and if it is set to 'html' don't encode a second
>> time?
>
> Addition:  This should only apply if encodeAsHTML() is used in GSPs ${...}
> expressions.
>   I don't know if this method could check for this context?

encodeAsHTML() has no way of knowing whether a string has already been
encoded or not. That's one of the problems. We don't keep track during
request processing of what encoding is currently active.

Also, examples of plugin pages that will break:

    show.gsp from the scaffolding
    https://github.com/grails-plugins/grails-spring-security-ui/blob/master/grails-app/views/user/create.gsp#L50

Sorry, don't have time to look for others. I'm sure Marc will list a
bunch of his plugins that use encodeAsHTML(). So it's a real problem
that we need to be wary of.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

Lari Hotari
16.08.2011 11:33, Peter Ledbrook wrote:

>
> encodeAsHTML() has no way of knowing whether a string has already been
> encoded or not. That's one of the problems. We don't keep track during
> request processing of what encoding is currently active.
>
> Also, examples of plugin pages that will break:
>
>     show.gsp from the scaffolding
>     https://github.com/grails-plugins/grails-spring-security-ui/blob/master/grails-app/views/user/create.gsp#L50
>
> Sorry, don't have time to look for others. I'm sure Marc will list a
> bunch of his plugins that use encodeAsHTML(). So it's a real problem
> that we need to be wary of.

btw. Marc has created a Jira issue some time ago which is related to
this discussion:
http://jira.grails.org/browse/GRAILS-7136
I've been thinking of the solution in the back of my head since then,
based on the ideas Marc presented in the jira issue.

Currently the output of gsps and taglibs uses StreamCharBuffer class
extensively.
We could add the tracking of which encoding has been applied to the
StreamCharBuffer class.

encodeAs* (Codec support in Grails) could be made to defer encoding
until the "final merging" and output of the buffer. Each sub-buffer
would have information about which Codec to use when it gets written to
the "final output" (=response).This would prevent "double encoding" and
make it possible to output parts which shouldn't be encoded (like html
content coming from a CMS) at all. It's also possible to improve /
optimize performance in this kind of solution. It would be optimal if
Codec's had some kind of streaming interface (java.io.Writer?) to be
able to apply the codec when it's written to the underlying Writer
(without doing extra string conversions).

I don't think this is a hard problem to solve since StreamCharBuffer is
already used in taglib & gsp output. It's just about extending
StreamCharBuffer's features.

Regards,

Lari

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
 sounds great.


On Tue, Aug 16, 2011 at 11:42 AM, Lari Hotari <[hidden email]> wrote:
16.08.2011 11:33, Peter Ledbrook wrote:
>
> encodeAsHTML() has no way of knowing whether a string has already been
> encoded or not. That's one of the problems. We don't keep track during
> request processing of what encoding is currently active.
>
> Also, examples of plugin pages that will break:
>
>     show.gsp from the scaffolding
>     https://github.com/grails-plugins/grails-spring-security-ui/blob/master/grails-app/views/user/create.gsp#L50
>
> Sorry, don't have time to look for others. I'm sure Marc will list a
> bunch of his plugins that use encodeAsHTML(). So it's a real problem
> that we need to be wary of.

btw. Marc has created a Jira issue some time ago which is related to
this discussion:
http://jira.grails.org/browse/GRAILS-7136
I've been thinking of the solution in the back of my head since then,
based on the ideas Marc presented in the jira issue.

Currently the output of gsps and taglibs uses StreamCharBuffer class
extensively.
We could add the tracking of which encoding has been applied to the
StreamCharBuffer class.

encodeAs* (Codec support in Grails) could be made to defer encoding
until the "final merging" and output of the buffer. Each sub-buffer
would have information about which Codec to use when it gets written to
the "final output" (=response).This would prevent "double encoding" and
make it possible to output parts which shouldn't be encoded (like html
content coming from a CMS) at all. It's also possible to improve /
optimize performance in this kind of solution. It would be optimal if
Codec's had some kind of streaming interface (java.io.Writer?) to be
able to apply the codec when it's written to the underlying Writer
(without doing extra string conversions).

I don't think this is a hard problem to solve since StreamCharBuffer is
already used in taglib & gsp output. It's just about extending
StreamCharBuffer's features.

Regards,

Lari

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
In reply to this post by pledbrook
> Also, examples of plugin pages that will break:
>   show.gsp from the scaffolding
>   https://github.com/grails-plugins/grails-spring-security-ui/blob/master/grails-app/views/user/create.gsp#L50
>
> Sorry, don't have time to look for others. I'm sure Marc will list a
> bunch of his plugins that use encodeAsHTML(). So it's a real problem
> that we need to be wary of.

Thanks for the feedback.

That means the spring-security-ui plugin and the bunch of others can't be used
with the 'html' default encoding, today?
For me these are bugs in the plugins.

Cheers,
Mos
---
http://www.mosbase.com/


On Tue, Aug 16, 2011 at 10:33 AM, Peter Ledbrook <[hidden email]> wrote:
>> Regarding encodeAsHTML() in general I would suggest a "default-checking":
>> Couldn't the method
>> just check the default and if it is set to 'html' don't encode a second
>> time?
>
> Addition:  This should only apply if encodeAsHTML() is used in GSPs ${...}
> expressions.
>   I don't know if this method could check for this context?

encodeAsHTML() has no way of knowing whether a string has already been
encoded or not. That's one of the problems. We don't keep track during
request processing of what encoding is currently active.

Also, examples of plugin pages that will break:

   show.gsp from the scaffolding
   https://github.com/grails-plugins/grails-spring-security-ui/blob/master/grails-app/views/user/create.gsp#L50

Sorry, don't have time to look for others. I'm sure Marc will list a
bunch of his plugins that use encodeAsHTML(). So it's a real problem
that we need to be wary of.

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

mos-7
In reply to this post by pledbrook
No changes in M2 for the default-codec ?

Cheers,
Mos
---
http://www.mosbase.com/


On Mon, Aug 8, 2011 at 2:30 PM, Peter Ledbrook <[hidden email]> wrote:
> Setting default codec to html on new projects will break an awful lot of plugins for people out of the box. This doesn't mean it is not a valid approach, but it has a high cost associated currently.

Grails 2.0 gives us an opportunity to introduce this change and get
plugin authors updating their GSP pages to use the defaultEncoding
page directive. It's not a perfect solution, but I think making pages
safer by default is worthwhile. And most existing applications will
have the default encoding as "none", so it wouldn't be a breaking
change for existing apps.

> We've had a lot of discussions about this, and evolved thinking, forgotten, and re-remembered and forgotten again :)

Indeed.

> * Add "encodeAs" or "codec" attribute to the GSP tag mechanism, so it is automatically applied to any and all tags with no effort from the tag author.  We already have encodeAs support on a few tags, but it is explicitly added. Example:
> <script …>
>    var url = "${g.createLink(controller:'book', encodeAs:'JavaScript')";
> </script>

The question is whether this should be 'additive'. In other words, the
URL should probably be URL encoded and then encoded as JavaScript.
That's additive. But perhaps there are examples where you want to
override the default encoding of a tag?

Anyway, I don't think we're that far away from a solution, but I can't
see all the above being introduced for Grails 2.0. So I still think
changing the default and encouraging plugin developers to update their
plugins is the best thing to do right now.

Peter

PS What's the best channel for communicating such changes to plugin
authors? Dev mailing list with a [FAO: Plugin authors]? Something
else?

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

pledbrook
> No changes in M2 for the default-codec ?

Let's try to build a plan for this. First off, we still need to decide
whether to do it. Outstanding issues are:

1. It will break some plugins. If we do this, we either need to ensure
that plugin authors put default encoding directives in their GSPs, or
Grails 2 assumes "none" for plugin views.

2. We need to check whether the fieldValue tag will be affected. If it
is, we may need to review others as well. It could very well be a
blocker.

If we do decide to go ahead, we need to evaluate whether it's feasible
to reset the default encoding for plugin views and partial templates
or not. If it is, then we should probably do that. Otherwise, we
simply focus on notifying plugin authors.

Ideally we could verify GSPs with something like CodeNARC, but I don't
think that's feasible. Mind you, GSPs are translated to Groovy, so
perhaps it's not too hard to do.

Anyway, I think that pretty much sums up the current state of play. If
it weren't for the above issues, we probably would have changed the
default encoding for  M2.

Cheers,

Peter

--
Peter Ledbrook
Grails Advocate
SpringSource - A Division of VMware

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

Ko-Chih Wu
I was working on XSS fixes in our own application. Is there any progress on this issue since the last reply is an year old.

Also there's a similar wiki talking about this: https://github.com/grails/grails-core/wiki/Default-Codecs/_history
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0: Change default-codec to ‘html’ ?

Jeff Brown-4

On Nov 27, 2012, at 5:13 PM, Ko-Chih Wu <[hidden email]> wrote:

> I was working on XSS fixes in our own application. Is there any progress on
> this issue since the last reply is an year old.
>

In some ways, this is a deceivingly complex issue.

Can you describe what you think the default behavior should be?



JSB

--
Jeff Brown
[hidden email]
SpringSource - A Division Of VMware
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...