Grokbase
Topics Posts Groups | in
x
[ help ]

Bill Moseley (mo...@hank.org)

Profile | Posts (287)Page 1 of 15: 1 2 3 > >>
1) Bill Moseley [Catalyst] Re: CSRF (plus session security)
| +1 vote
Ya, but it's valid for multiple posts. That might be ok, but in general, I only want one post for...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Wed, Oct 01, 2008 at 12:20:04PM +0200, Aristotle Pagaltzis wrote:
> * Moritz Onken <onken@houseofdesign.de> [2008-10-01 09:25]:
> > The best way is to include a random string which has to be
> > stored somewhere for comparison on the server side.
>
> Doesn?t have to be stored. Send a random string as well as a HMAC
> digest of a server secret plus the same string. To check a token,
> check if the random string plus server secret hash to the same
> digest as the one provided by the client. Since the server secret
> is not known or knowable to third parties, if the digest checks
> out, then this token must have been minted by the server. Very
> simple; near-zero CPU overhead; no server-side storage required.

Ya, but it's valid for multiple posts.  That might be ok, but in
general, I only want one post for every one form generation (and no
post without a form being generated).

So, my forms all have a unique token that can only be used once.  If
used a second time I redisplay the form pre-filled with their post and
ask them to submit again if that's what they really intended.  That
has the benefit of catching if the form is no longer valid (due to
changes in the database from the first post).

Of course, that doesn't prevent using two browser windows, etc. but it
helps.


Let me ask a related question:

Where on the risk spectrum is CSRF compared to, say, session
hijacking?

I have an application that went from having some pages SSL encrypted
to all pages encrypted for logged in users.

I would like to only use secure cookies, but I place things in the
session that I need for both SSL and non-SSL pages (an example is a
language selection that is stored in the session).[1]

Makes me think I need $c->session and also $c->secure_session as
separate sessions and separate cookies.


--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
2) Bill Moseley [Catalyst] Passing UTF-8 arg in URL to DBIC search
| +1 vote
I think Encode::decode_utf8() the recommended method over using the utf8::decode call. Perhaps...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, Sep 30, 2008 at 08:10:13AM -0700, J. Shirley wrote:
> On Sat, Sep 27, 2008 at 6:51 AM, Hugh Hunter <hhunter@gmail.com> wrote:
> > Hello all,
> >
> > I've been struggling with this for some time and know there must be an
> > answer out there.
> >
> > I'm using URL arguments to pass parameters to my controller. It's a site
> > about names, so take the url http://domain.com/name/Jes?s (note the accented
> > u). The Name.pm controller has an :Args(1) decorator so Jes?s is stored in
> > $name and then passed to my DBIC model in a ->search({name => $name}) call.
> > This doesn't manage to find the row that exists in mysql. When I dump
> > $name I get:
> >
> > 'name' => 'Jes\xc3\xbas'
> >
> > which I think I understand as being perl's internal escaping of utf-8
> > characters.
> >
> > I've done everything recommended on
> > http://dev.catalystframework.org/wiki/gettingstarted/tutorialsandhowtos/using_unicode and
> > the name column in my mysql database uses the utf-8 charset.
> >
> > Where am I going wrong?
> >
> > Best regards,
> >
> > --Hugh
>
> I haven't dug into the Catalyst source to see of any handling for the
> arguments, but just for testing you may want to try doing a
> utf8::decode($name) and see if that does the trick for you.

I think Encode::decode_utf8() the recommended method over using the
utf8::decode call.  Perhaps something like this early in the request:

    $c->req->arguments(
        [
            map { Encode::decode_utf8($_) } @{$c->req->arguments}
        ]
    );

But, I'd be concerned about doing this.  Will all browsers encode into
utf8 octets?  You could easily make an LWP request with other
encodings.


--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
3) Bill Moseley [Catalyst] Passing UTF-8 arg in URL to DBIC search
| +1 vote
The plugin does not decode the path, only the query parameters.[1] I'm not clear on passing utf8 on...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Sat, Sep 27, 2008 at 09:51:54AM -0400, Hugh Hunter wrote:
>
> I'm using URL arguments to pass parameters to my controller. It's a
> site about names, so take the url http://domain.com/name/Jes?s (note
> the accented u). The Name.pm controller has an :Args(1) decorator so
> Jes?s is stored in $name and then passed to my DBIC model in a -
> >search({name => $name}) call. This doesn't manage to find the row
> that exists in mysql.  When I dump $name I get:
>
>
> I've done everything recommended on
> http://dev.catalystframework.org/wiki/gettingstarted/tutorialsandhowtos/using_unicode
> and the name column in my mysql database uses the utf-8 charset.
> Where am I going wrong?

The plugin does not decode the path, only the query parameters.[1]


I'm not clear on passing utf8 on the path -- I thought you would have
to url-encode it, but maybe the browser will do that. Although, I'm not
clear how it knows what encoding to use.


[1] also note that it doesn't decoded the body params, so if you
access those via the body_parameters request method they won't be
decoded.  Accessing them via ->parameters is ok, though.

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
4) Bill Moseley [Catalyst] Pushing data to Catalyst powered web page
| +1 vote
Pull with an AJAX update, perhaps.
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Fri, Sep 12, 2008 at 02:15:23PM +0200, Supra, Morne wrote:
>
> The problem that I have is that I have no idea how to push the data to a
> web page instead of pulling.

Pull with an AJAX update, perhaps.

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
5) Bill Moseley [Catalyst] HTTP::Body, Catalyst, and death.
| +1 vote
Catalyst::Engine prepare_body_chunk() calls HTTP::Body's add() method with chunks as they are read...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
Catalyst::Engine prepare_body_chunk() calls HTTP::Body's add() method
with chunks as they are read from the input stream.

What happens if the call to ->add($chunk); dies?  Does the input
stream get somehow flushed (up to the content_length)?  Or would the
exception bypass any flushing?

In other words, is it important that HTTP::Body's add() method (and
really, spin() ) not die and instead continue to, well, spin until all
the request data has been consumed?


--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
6) Bill Moseley [Catalyst] Apache2::RequestIO::read problem
| +1 vote
I see these, too. I've not been too worried, and I've been assuming that Apache is just falling...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, Jul 29, 2008 at 12:07:31AM -0500, Chris Dolan wrote:
>
> [error] Caught exception in engine "Apache2::RequestIO::read: (104)
> Connection reset by peer at /home/foo/perl/lib/perl5/site_perl/5.8.8/
> Catalyst/Engine/Apache.pm line 187"
> [Mon Jul 28 16:14:36 2008] [error] [client xxx.xxx.xxx.xxx] File does
> not exist: /home/foo/MyApp/root/student, referer: http://example.com/
> student
>
> I think the "connection reset" part is a client disconnecting
> prematurely, but what disturbs me is the second error. I have a lib/
> MyApp/Controller/Student.pm which should be receiving requests to
> http://example.com/student, but instead I see those requests
> redirected to my static folder (.../root/...). This does not happen
> normally -- plenty of hits are going through to /student as expected.

I see these, too.  I've not been too worried, and I've been assuming
that Apache is just falling back to the default handler for some
reason.

There's a little info to be found with Google -- mostly others asking
the same question.

It would be nice to have these fail in a cleaner way (as far as the
logs go, at least).

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
7) Bill Moseley [Catalyst] API Versioning for Web Services
| +1 vote
I completely agree. I suppose a "version" XMLRPC parameter in the request payload is possible, but...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Sun, Jul 27, 2008 at 06:42:23PM -0500, [email protected: Wade.S...@fallon.com] wrote:
> >     widget.1.get
> >     widget.2.get
> >     etc.
> >
> Icky, I think the API should be versioned -- not methods. What if
> the methods across versions are not compatible (widget1 output used with
> foo2) versioning the api forces all methods to be used with their tested
> and versioned partners. When you have 30 or 40 different revisions and
> developers start relying on mismatching methods from different versions
> that seems like a headache waiting to happen.

I completely agree.

I suppose a "version" XMLRPC parameter in the request payload is
possible, but I'm actually leaning more toward just using separate
endpoints:

    http://localhost:3000/rpc1.2
    http://localhost:3000/rpc1.3

or

    http://localhost:3000/rpc/1.2
    http://localhost:3000/rpc/1.3

or

    http://localhost:3000/rpc?version=1.2

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
8) Bill Moseley [Catalyst] API Versioning for Web Services
| +1 vote
C::Action::REST uses "ActionClass('REST')" to specify the class for the action. And with a custom...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Sat, Jul 26, 2008 at 06:00:39AM +0100, Matt S Trout wrote:
>
> sub widget :Local VersionedXMLRPC('widget.get') {
>
> sub widget_xmlrpc_v1 {
>
> have VersionedXMLRPC apply a custom a ction class that does ->can
> based dispatch, same way Catalyst::Action::REST does.

C::Action::REST uses "ActionClass('REST')" to specify the class for
the action.  And with a custom request class, has a custom dispatcher to
dispatch based on the request method.

Your example above does not use ActionClass.  Were you suggesting that
these XMLRPC actions have their own action class, and if so how would
the actions be setup then?

I would think the Catalyst approach would be something like this:

    sub widget : Local ActionClass('XMLRPC', 'widget.get' ) {


There's more than one approach, of course.

My current approach (w/o versioning) is to have a custom dispatcher
type (which I push onto $c->dispatcher->preload_dispatch_types).  I
also have a custom HTTP::Body type to parse the XMLRPC payload.  Once
the XMLRPC method name is known from the request the dispatcher
searches for the matching action.

But, I do like the approach of matching the action, and then using
$controller->can to try and find an appropriate version as you
suggested.

By the way, my assumption is I would have the entire XMLRPC API
versioned.  I asked about this on the XMLRPC list and it was
recommended that instead I version individual methods.  That is, have
separate method names that include a version:

    widget.1.get
    widget.2.get
    etc.

which would make the Catalyst part very simple, but I'm not sure I
like that idea of each method having a version in the method name.

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
9) Bill Moseley [Catalyst] API Versioning for Web Services
| +1 vote
I'm looking for suggestions how to best support multiple API versions in an application. The API...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
I'm looking for suggestions how to best support multiple API versions
in an application.

The API and web share many controller actions.  As is not uncommon,
actions available for the API are defined with an attribute:

    sub foo : Local XMLRPC( 'foo.get' ) {

This is great for sharing code as often the API just exposes
the same functionality as the web interface.


When a new version of the web application is released then all web
users see the new version at the same time.  If an action in the new
version expects an additional new parameter then the form posting to
that action is modified at the same time.

But, the API access to an application typically needs to be backward
compatible to allow API users time to update their client applications
with the newer requirements.

So, it seems I would need multiple controller actions that are
dispatched based on some version.


Here's one idea I was kicking around:

Say I have an existing controller action that is used by the web
users, but also available as an XMLRPC API method:

    sub widget : Local XMLRPC( 'widget.get' ) {

So in a new application version that controller action is changed
and now requires a new parameter and returns new data.

In the new version I want to support the new action but remain
backward compatible.

    # fetch widget for web and API
    sub widget : Local XMLRPC( 'widget.get' ) Version( 2 ) {

    # deprecated to support old version of API
    sub widget_old : XMLRPC( 'widget.get' ) Version( 1 ) {

Then in my custom API dispatcher match method I take the version into
consideration when matching actions.


Any better suggestions?



--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
10) Bill Moseley [Catalyst] Using a post argument in a template
| +1 vote
You said argument in your original post: sub foo : Local { my ( $self, $c, $myarg ) = @_;...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Fri, Jul 25, 2008 at 07:40:59AM -0500, James S. White wrote:
> I was trying to munge the paramaters in the controller,

You said argument in your original post:

    sub foo : Local {
        my ( $self, $c, $myarg ) = @_;

        $c->stash->{myarg} = $self->munge( $myarg );
        # or use chaining
    }


> I just can't figure
> out how to access the variables of a controller method in the template.

    Munged argument is [% myarg | html %]


> I'd
> be more than happy to pass the argument to a controller, and then have the
> view fetch it from the controller, and then the template read it from the view,
> If I had any idea how to dereference the variables in order to set them in
> new components. I was just trying to keep it walk before running and I keep
> tripping over my feet.

It's that wording that is tripping me up. ;)







>
>
> On Fri, 25 Jul 2008, Eden Cardim wrote:
>
> > On Fri, Jul 25, 2008 at 1:12 AM, James S. White <james@jameswhite.org> wrote:
> > > I'm passing an argument to the method via a post, and then catch it with
> > > my ( $self, $c, $myarg ) = @_; shouldn't there be a way to mine it without
> > > using [% c.req.arguments.0 %] in the template?
> > >
> > > like [% c.controller('Page').methodname.myarg %] or something...
> >
> > You want [% c.req.body_params.myarg %] if it's a post, [%
> > c.req.params.myarg %] if you don't care. I would munge the parameters
> > in the controller and try to formalize an API to interact with the
> > view though. Also, avoid making your view-side code be
> > controller-dependent, you'll surely regret it later.
> >
> > --
> > edenc.vox.com
> >
>
>
> _______________________________________________
> List: [email protected: Cat...@lists.scsys.co.uk]
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
11) Bill Moseley [Catalyst] Preventing simultaneous logins
| +1 vote
And what happens if they never hit log out? Or if their browser crashes and then they try and log...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Wed, Jul 23, 2008 at 09:47:57PM +0200, Daniel McBrearty wrote:
> What I'd like to do is check if this user is already logged in at some
> other computer, and deny access if so. I guess that means :
>
> 1. checking whether there is an existing session associated this username
> 2. Being sure that the associated session is cleared when the user hits 'logout'

And what happens if they never hit log out?  Or if their browser
crashes and then they try and log in again?

If you really need this feature, try it the other way around:  if
someone logs in then you invalidate their first session.

--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
12) Bill Moseley [Catalyst] Any recommendations for multiple forms in catalyst (have been using HTML::FormFu)?
| +1 vote
Have not been following that closely, but that looks complicated. I would do something like this...
catalyst@lists.scsys.co.uk
[ Profile | Reply to group ] [ Flat  Thread  Threaded ]
On Tue, Jul 15, 2008 at 11:13:34PM +1000, [email protected: kak...@tpg.com.au] wrote:
> hi
> I was pretty successful in keeping things simple.
>
>
> sub create :Local :FormMethod('_get_dynamic_form') {
>     my ($self, $c) = @_;
>
>     # Set the template
> my $effective_template = 'listings/create.tt2';
> $c->stash->{template} = $effective_template;
> my $loanType = lc($c->request->param('loanType'));
>
>     my $step = $c->flash->{step};
> $c->log->debug("Current operation: $step");
>
>     if (defined($step) and $step =~ m/\w+/)
>     {
> my $form_submission_success = $c->stash->{'form'}->submitted();
>         if ($form_submission_success) {
>
>             if ($step eq 'first_step')
>             {
>                ....
>
>
>              # now, set the next step.
> $c->flash->{'step'} = 'second_step';
>            } 
>            elsif ($step eq 'second_step')
>            {
>              ....
>
>   
>              # now, set the next step.
> $c->flash->{'step'} = 'third_step';
>
>            }
>            elsif ($step eq 'third_step')
>            {
>              ....
>
>   
> # now, we have acquired all data we need from steps one and
> two.
> # we do a redirect/forward/detach to save the values.
> Should go to 'sub save_complete_listing'
>
> $c->detach/ $c->res->forward/$c->redirect # all failed.
>            }


Have not been following that closely, but that looks complicated.
I would do something like this with Form::Processor:

    sub first_step : Local {
        my ( $self, $c ) = @_;

        return $c->post_redirect( 'second_step' )
            if $c->update_from_form;
    }


    sub second_step : Local {
        my ( $self, $c ) = @_;

        return $c->redirect( 'first_step' )
            unless $c->session->{first_step};

        return $c->post_redirect( 'third_step' )
            if $c->update_from_form;

    }


    sub third_step : Local {
        my ( $self, $c ) = @_;

        return $c->redirect( 'second_step' )
            unless $c->session->{second_step};

        return $c->post_redirect( '/home', 'Thanks for your order' )
            if $c->update_from_form:
    }

My forms are classes, thus each form class knows to save their data in the
session (except third_step which writes all the form data).  They also
know how to pre-populate the form from a previous submission (for
example, if someone goes from form three back to form one.

update_from_form() knows the form class from the action name, and
$c->redirect and $c->post_redirect are simple short-cut methods to
build the redirect and localize any messages that end up in flash.


--
Bill Moseley
[email protected: mo...@hank.org]
Sent from my iMutt
13) Bill Moseley [Catalyst] Capture page on server?