You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Oliver Pfeiffer <ol...@icip.ch> on 2009/07/29 16:07:11 UTC
Beginner question: script resolution
Hi all,
I recently discovered Sling and I would like to use it with the
server-side-script functionality only in a small project.
I have a beginner question regarding the script-location resolution:
1.Let's say I have the following ressource "/content/homepage/blog" (with
"sling:resourceType" set to "homepage/blog")
Now "/content/homepage/blog.list.html" is calling
"/apps/homepage/blog/list.html.eps". This works nicely
2. Let's say I have a first blog-entry at "/content/homepage/blog/entry1"
(with "sling:resourceType" set to "homepage/blog")
and I want to edit with "/content/homepage/blog/entry1.edit.html" which
calls "/apps/homepage/blog/edit.html.eps". This works nicely
3. Now I want to add a new blog-entry:
with "content/homepage/blog/*.edit.html" I would like to call
"/apps/homepage/blog/edit.html.eps" as well. Unfortunately Sling will
look for the "edit.html.eps"-script unter "apps/homepage" (which I don't
know why exactly) and not "/apps/homepage/blog".
How could I define the "sling:resourceType" for the new ressource, so that I
can use the same "edit.html.eps"-file for edit and insert?
Thanks in advance.
Cheers
Oliver
Re: Beginner question: script resolution
Posted by Oliver Pfeiffer <ol...@icip.ch>.
Thanks a lot for your hints and the small discussion.
In a first step I will propably go on with my small project without the
directory structure for my scripts I had in mind. :-)
Thanks again.
Regards,
Oliver
2009/7/30 Alexander Klimetschek <ak...@day.com>
> On Thu, Jul 30, 2009 at 3:05 PM, Ian Boston<ie...@tfd.co.uk> wrote:
> > I might be missing the point, but,
> > I think this is a generic problem not just limited to this area, if I can
> > create a node and set sling:resourceType=something/nasty, *and* upload an
> > arbitrary script to somewhere that is resoled to by "something/nasty" ,
> then
> > I can do the same in 2 steps ?
> >
> > IIRC, there is some work in progress to limit how scripts are loaded, but
> it
> > may not extend as far as protecting the location.
>
> You are right, I forgot about that issue. So basically one has to make
> sure anonymous or "public" users (ie. through self-registration)
> cannot set resource types (which would require an ACL on the
> sling:resourceType/sling:superResourceType properties, which isn't
> possible with JCR 1.0 or 2.0) or simply has only write-access to
> locations that are not part of the script resolution search path.
>
> > also... how does a script resolve *outside* /apps ?
>
> You can use an absolute path... at least in Java servlets with the
> sling.servlet.paths SCR property. Not sure if this applies to
> sling:resourceType as well.
>
> >> :name and :nameHint are not enough?
> >
> > yes, for names like /content/new/a_file_that_was_hinted
> >
> > but not so good for
> >
> > /content/new/a/file/that/was/hinted
> > where the name is a path, perhaps derived from the post.
>
> Yes, this use case must be handled on the client side (eg. Javascript
> in browsers), to set the path before the post.
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>
--
Dr. Oliver Pfeiffer
Individual Computing GmbH
Ingelsteinweg 2d, 4143 Dornach
Tel.: +41 61 511 23 63
E-Mail: oliver.pfeiffer@individual-computing.com
Web: www.individual-computing.com
Re: Beginner question: script resolution
Posted by Carsten Ziegeler <cz...@apache.org>.
Carsten Ziegeler wrote:
> Yes, you can mount a Java servlet (must be a proper OSGi service) to any
> resource path. Then you can invoke this servlet by accesing this path.
> For example if you mount the servlet to "/no/one/knows/this/path", you
> can call this servlet from the browser by exactly that path.
> Maybe this is something we should reconsider and forbid?
>
> But scripts for rendering are always only searched under the configured
> search paths. There is no way around it.
>
Ok, actually I was wrong :) If you specify an absolute resource type
like "/execute/me" the script is taken from this location.
Carsten
--
Carsten Ziegeler
cziegeler@apache.org
Re: Beginner question: script resolution
Posted by Carsten Ziegeler <cz...@apache.org>.
Alexander Klimetschek wrote:
> On Thu, Jul 30, 2009 at 3:05 PM, Ian Boston<ie...@tfd.co.uk> wrote:
>> I might be missing the point, but,
>> I think this is a generic problem not just limited to this area, if I can
>> create a node and set sling:resourceType=something/nasty, *and* upload an
>> arbitrary script to somewhere that is resoled to by "something/nasty" , then
>> I can do the same in 2 steps ?
>>
>> IIRC, there is some work in progress to limit how scripts are loaded, but it
>> may not extend as far as protecting the location.
>
> You are right, I forgot about that issue. So basically one has to make
> sure anonymous or "public" users (ie. through self-registration)
> cannot set resource types (which would require an ACL on the
> sling:resourceType/sling:superResourceType properties, which isn't
> possible with JCR 1.0 or 2.0) or simply has only write-access to
> locations that are not part of the script resolution search path.
Current trunk uses a configurable script admin user to read scripts from
the configured search paths. So by making these trees only writeable
(and maybe readable) for the script admin should prevent the average
user from adding scripts to the system.
>
>> also... how does a script resolve *outside* /apps ?
>
> You can use an absolute path... at least in Java servlets with the
> sling.servlet.paths SCR property. Not sure if this applies to
> sling:resourceType as well.
Yes, you can mount a Java servlet (must be a proper OSGi service) to any
resource path. Then you can invoke this servlet by accesing this path.
For example if you mount the servlet to "/no/one/knows/this/path", you
can call this servlet from the browser by exactly that path.
Maybe this is something we should reconsider and forbid?
But scripts for rendering are always only searched under the configured
search paths. There is no way around it.
Carsten
>
>>> :name and :nameHint are not enough?
>> yes, for names like /content/new/a_file_that_was_hinted
>>
>> but not so good for
>>
>> /content/new/a/file/that/was/hinted
>> where the name is a path, perhaps derived from the post.
>
> Yes, this use case must be handled on the client side (eg. Javascript
> in browsers), to set the path before the post.
>
> Regards,
> Alex
>
--
Carsten Ziegeler
cziegeler@apache.org
Re: Beginner question: script resolution
Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Jul 30, 2009 at 3:05 PM, Ian Boston<ie...@tfd.co.uk> wrote:
> I might be missing the point, but,
> I think this is a generic problem not just limited to this area, if I can
> create a node and set sling:resourceType=something/nasty, *and* upload an
> arbitrary script to somewhere that is resoled to by "something/nasty" , then
> I can do the same in 2 steps ?
>
> IIRC, there is some work in progress to limit how scripts are loaded, but it
> may not extend as far as protecting the location.
You are right, I forgot about that issue. So basically one has to make
sure anonymous or "public" users (ie. through self-registration)
cannot set resource types (which would require an ACL on the
sling:resourceType/sling:superResourceType properties, which isn't
possible with JCR 1.0 or 2.0) or simply has only write-access to
locations that are not part of the script resolution search path.
> also... how does a script resolve *outside* /apps ?
You can use an absolute path... at least in Java servlets with the
sling.servlet.paths SCR property. Not sure if this applies to
sling:resourceType as well.
>> :name and :nameHint are not enough?
>
> yes, for names like /content/new/a_file_that_was_hinted
>
> but not so good for
>
> /content/new/a/file/that/was/hinted
> where the name is a path, perhaps derived from the post.
Yes, this use case must be handled on the client side (eg. Javascript
in browsers), to set the path before the post.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Beginner question: script resolution
Posted by Ian Boston <ie...@tfd.co.uk>.
On 30 Jul 2009, at 10:08, Alexander Klimetschek wrote:
> On Thu, Jul 30, 2009 at 10:46 AM, Ian Boston<ie...@tfd.co.uk> wrote:
>> Looking at [3], 2 things jump out.
>> 1. On post @typeHint gives a hint for the type of a property, If when
>> posting to a non existing resource you could pick up the resource
>> type from
>> the post sling:resourceType POST parameter would it be possible to
>> perform
>> the servlet resolution appropriately. Ie its still a non existing
>> resource,
>> but it gets routed to the correct servlet ?
>
> This is probably not safe, because if any resource type = script
> selector is injected from the outside, you can upload and run
> arbitrary scripts on the server, provided you have rights to modify
> content at one part of the repository (eg. /tmp for uploads). It is
> possible to restrict against such an attack by additional guarding
> (eg. restricting the script user, not allowing resource types located
> in /tmp), but the generality of this issue makes it easy to have a
> hole open in a running system.
I might be missing the point, but,
I think this is a generic problem not just limited to this area, if I
can create a node and set sling:resourceType=something/nasty, *and*
upload an arbitrary script to somewhere that is resoled to by
"something/nasty" , then I can do the same in 2 steps ?
IIRC, there is some work in progress to limit how scripts are loaded,
but it may not extend as far as protecting the location.
also... how does a script resolve *outside* /apps ?
>
>> 2. (slightly off track) when posting to /content/new/* a path
>> generation
>> algorithm kicks in, being able to configure that algorithm might
>> help with
>> some of the virtual cases (probably should talk about this in another
>> thread)
>
> :name and :nameHint are not enough?
yes, for names like /content/new/a_file_that_was_hinted
but not so good for
/content/new/a/file/that/was/hinted
where the name is a path, perhaps derived from the post.
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
Re: Beginner question: script resolution
Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Jul 30, 2009 at 10:46 AM, Ian Boston<ie...@tfd.co.uk> wrote:
> Looking at [3], 2 things jump out.
> 1. On post @typeHint gives a hint for the type of a property, If when
> posting to a non existing resource you could pick up the resource type from
> the post sling:resourceType POST parameter would it be possible to perform
> the servlet resolution appropriately. Ie its still a non existing resource,
> but it gets routed to the correct servlet ?
This is probably not safe, because if any resource type = script
selector is injected from the outside, you can upload and run
arbitrary scripts on the server, provided you have rights to modify
content at one part of the repository (eg. /tmp for uploads). It is
possible to restrict against such an attack by additional guarding
(eg. restricting the script user, not allowing resource types located
in /tmp), but the generality of this issue makes it easy to have a
hole open in a running system.
> 2. (slightly off track) when posting to /content/new/* a path generation
> algorithm kicks in, being able to configure that algorithm might help with
> some of the virtual cases (probably should talk about this in another
> thread)
:name and :nameHint are not enough?
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Beginner question: script resolution
Posted by Ian Boston <ie...@tfd.co.uk>.
I should add that [1] is certainly not finalized as a patch since it
has some major issues with the way it needs to change core api's in a
non compatible way
I have been trying on and off to eliminate those problems (using a
SyntheticResource)... but at the moment so the best way of delivering
what is in 1023 at the moment is to use the /apps/sling/nonexisting/
POST.esp mechanism.
---------------------
Looking at [3], 2 things jump out.
1. On post @typeHint gives a hint for the type of a property, If when
posting to a non existing resource you could pick up the resource type
from the post sling:resourceType POST parameter would it be possible
to perform the servlet resolution appropriately. Ie its still a non
existing resource, but it gets routed to the correct servlet ?
2. (slightly off track) when posting to /content/new/* a path
generation algorithm kicks in, being able to configure that algorithm
might help with some of the virtual cases (probably should talk about
this in another thread)
Ian
On 29 Jul 2009, at 23:36, Alexander Klimetschek wrote:
> On Wed, Jul 29, 2009 at 4:07 PM, Oliver Pfeiffer<oliver.pfeiffer@icip.ch
> > wrote:
>> 3. Now I want to add a new blog-entry:
>> with "content/homepage/blog/*.edit.html" I would like to call
>> "/apps/homepage/blog/edit.html.eps" as well. Unfortunately Sling will
>> look for the "edit.html.eps"-script unter "apps/homepage" (which I
>> don't
>> know why exactly) and not "/apps/homepage/blog".
>> How could I define the "sling:resourceType" for the new ressource,
>> so that I
>> can use the same "edit.html.eps"-file for edit and insert?
>
> For non-existent resources the case is a bit different: as Sling
> cannot know what the resource type is (and guessing by parent path is
> too fragile), Sling will resolve the resource with the type
> "sling:nonexisting" (NonExistingResource class). Therefore scripts or
> servlets that should handle that must be registered under
> /apps/sling/nonexisting/POST.esp. And note that this will be the same
> script for all kinds of non-existent resources. See [1] and [2] for
> some ideas/manual solutions on how to improve that use case.
>
> For content-creation (from a browser) the "standard" Sling way is to
> use normal HTML forms + the Sling post servlet and a
> SlingPostOperation or SlingPostProcessor for any additional
> server-side handling of the post [3].
>
> [1] https://issues.apache.org/jira/browse/SLING-1023
> [2] http://markmail.org/message/52m32zh36ewo4xl2
> [3] http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
Re: Beginner question: script resolution
Posted by Alexander Klimetschek <ak...@day.com>.
On Wed, Jul 29, 2009 at 4:07 PM, Oliver Pfeiffer<ol...@icip.ch> wrote:
> 3. Now I want to add a new blog-entry:
> with "content/homepage/blog/*.edit.html" I would like to call
> "/apps/homepage/blog/edit.html.eps" as well. Unfortunately Sling will
> look for the "edit.html.eps"-script unter "apps/homepage" (which I don't
> know why exactly) and not "/apps/homepage/blog".
> How could I define the "sling:resourceType" for the new ressource, so that I
> can use the same "edit.html.eps"-file for edit and insert?
For non-existent resources the case is a bit different: as Sling
cannot know what the resource type is (and guessing by parent path is
too fragile), Sling will resolve the resource with the type
"sling:nonexisting" (NonExistingResource class). Therefore scripts or
servlets that should handle that must be registered under
/apps/sling/nonexisting/POST.esp. And note that this will be the same
script for all kinds of non-existent resources. See [1] and [2] for
some ideas/manual solutions on how to improve that use case.
For content-creation (from a browser) the "standard" Sling way is to
use normal HTML forms + the Sling post servlet and a
SlingPostOperation or SlingPostProcessor for any additional
server-side handling of the post [3].
[1] https://issues.apache.org/jira/browse/SLING-1023
[2] http://markmail.org/message/52m32zh36ewo4xl2
[3] http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com