You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Matt Sergeant <ma...@sergeant.org> on 2003/01/26 11:46:47 UTC
Mitigating XSS in the mod_perl API
At the moment it's possible to do nasty XSS things in mod_perl when you
set a cookie. That's because $r->headers_out->add() (or set()) doesn't
care if you include carriage returns in your header. Simple example
would be:
$r->headers_out->add('Set-Cookie' => 'mycookie=' .
$r->param('myparam'));
Just stick a couple of carriage returns in myparam and you can get the
result:
Date: Sun, 26 Jan 2003 10:39:41 GMT
Server: Apache/1.3.26 (Unix) AxKit/1.6_01 mod_perl/1.27
Client-Date: Sun, 26 Jan 2003 10:39:42 GMT
Client-Response-Num: 1
Set-Cookie: mycookie=foo
<javascript>
....
</javascript>
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain; charset=ISO-8859-1
Thus giving you a full blown XSS bug.
Now wouldn't it be simple to just ban \n's in headers_out()? Throw an
exception or something? It might be a bit tricky because headers_out is
just a plain Apache table, but there's probably a way.
I suppose the opposition is that well, mod_perl is just an API, and we
shouldn't be forcing programming styles onto the programmer, but there
isn't a single legitimate use of \n in an outgoing header, so I don't
think that argument has much weight.
Thoughts?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Mon, Jan 27, 2003 at 03:07:01PM +0000, Matt Sergeant wrote:
> Anyway the main reason for doing this is there's no other way. Since
> headers_out is just a plain table object, and there are no "setter" hooks
> for tables, so I couldn't do it in mod_perl space. And I couldn't do it in
> AxKit space, so I had to patch Apache, which has a single exit point for
> all headers. I find it quite disappointing that people don't support
> fixing security issues here :-/
Please, you where the one that posted this snippet of code in the first
place:
$r->headers_out->add('Set-Cookie' => 'mycookie=' .
$r->param('myparam'));
I do support fixing security issues, and to all fairness you should have
brought this to security@apache.org's attention.
<quote from security buletin>
As a reminder, we respectfully request that anyone who finds a potential
vulnerability in our software reports it to security@apache.org.
</quote>
I've given my two cents and so have you, you said you posted a patch to
dev@httpd that fixes it in the right place and I applaud that.
/Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Tue, Jan 28, 2003 at 11:30:18AM +0000, Matt Sergeant wrote:
> Here's the patch in case anyone is interested in applying it to their own
> apache. I think there's probably a bug in that \n might not always be the
> right thing to look for (CRLF issues), so please send me corrections ;-)
>
> I haven't actually run this, so it might not work. But to quote Lord
> Flashheart: "That's the kind of guy I am". :-)
>
> Index: src/main/http_protocol.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/main/http_protocol.c,v
> retrieving revision 1.329
> diff -u -r1.329 http_protocol.c
> --- src/main/http_protocol.c 3 Oct 2002 20:51:53 -0000 1.329
> +++ src/main/http_protocol.c 28 Jan 2003 11:26:37 -0000
> @@ -1561,8 +1561,16 @@
> const char *fieldname,
> const char *fieldval)
> {
> + char *line_feed;
> if (strcasecmp(fieldname, "ETag") == 0) {
> if (ap_table_get(r->notes, "no-etag") != NULL) {
> + return 1;
> + }
> + }
> + if ((line_feed = strchr(fieldval, '\n')) != NULL) {
> + /* don't allow any headers with line feeds in them */
> + if (line_feed[1] != ' ' && line_feed[1] != '\t') {
> + /* unless it's a continuation */
> return 1;
> }
> }
I'm wondering if it's not smarter to go over fieldval and at the first
occourance of a \r or \n terminate the line there? I think there will
be more problems by just not outputting the headers in the first place.
Something like:
--- http_protocol.c.old Mon Jan 27 09:45:57 2003
+++ http_protocol.c Tue Jan 28 08:54:37 2003
@@ -1561,10 +1561,14 @@
const char *fieldname,
const char *fieldval)
{
+ char *f;
if (strcasecmp(fieldname, "ETag") == 0) {
if (ap_table_get(r->notes, "no-etag") != NULL) {
return 1;
}
+ }
+ if ((f = strchr(fieldval, '\r')) != NULL || (f = strchr(fieldval, '\n')) != NULL) {
+ *f = '\0';
}
return (0 < ap_rvputs(r, fieldname, ": ", fieldval, CRLF, NULL));
}
Of course, a check for continuation like in your patch is needed.
Attached is a module to test it with
Re: Mitigating XSS in the mod_perl API
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Matt Sergeant <ma...@sergeant.org> writes:
> On Thursday, Jan 30, 2003, at 15:24 Europe/London, Thomas Eibner wrote:
[...]
> > Are they being responsive or?
>
> No, I don't even think it got past non-subscriber moderation. However
> my original patch was naive, and didn't account for continuations.
>
> So I'm going to clean it up a bit more and post it as a bug report on
> bugzilla (though bugzilla doesn't seem to be sending me a password, so
> maybe I'll post it to bugtraq and just piss someone off ;-)
I feel your pain, brother :-)
--
Joe Schaefer,
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matt Sergeant <ma...@sergeant.org>.
On Thursday, Jan 30, 2003, at 15:24 Europe/London, Thomas Eibner wrote:
> What I was thinking was just that since you can add a header with
> $r->headers_out->add it would be possible to add something there to
> remove newlines, but since it's probably just an Apache::Table
> operation
> it wouldn't "know" which table it is working on either.
> Actually getting it fixed in Apache will probably benefit many other
> people and not just modperl users (not probably, it will!)
>
> Are they being responsive or?
No, I don't even think it got past non-subscriber moderation. However
my original patch was naive, and didn't account for continuations.
So I'm going to clean it up a bit more and post it as a bug report on
bugzilla (though bugzilla doesn't seem to be sending me a password, so
maybe I'll post it to bugtraq and just piss someone off ;-)
Matt.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Thu, Jan 30, 2003 at 02:36:53PM +0000, Matt Sergeant wrote:
> > And I don't really think it's designed to output a header. Tables where
> > used because it made it easy to implement (I assume), and it's only in
> > mod_perl and not the C api that there are specific functions for adding
> > to r->headers_out and r->err_headers_out, so ultimatively if anything
> > should deal with it, it's either the mod_perl functions OR as Matt has
> > submitted around line 1570 (in my non-up-to-date cvs copy) in
> > http_protocol.c, and yes, I do believe it's the right thing to do so you
> > can't output \n nor \r's in headers.
>
> I'm not really sure it's possible to fix in mod_perl either. Otherwise I
> would have done it there because I find it easier to maintain a patched
> mod_perl than a patched Apache.
What I was thinking was just that since you can add a header with
$r->headers_out->add it would be possible to add something there to
remove newlines, but since it's probably just an Apache::Table operation
it wouldn't "know" which table it is working on either.
Actually getting it fixed in Apache will probably benefit many other
people and not just modperl users (not probably, it will!)
Are they being responsive or?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matt Sergeant <ma...@sergeant.org>.
On Tue, 28 Jan 2003, Thomas Eibner wrote:
> Yes, that sounds very weak. To me it sounds like Matt doesn't know what
> he is doing if he's passing RAW input from a client directly into
> something. I know it sounds harsh and I'm not trying to degrade Matt as
> I have great respect for the work he is and has been doing for Perl and
> mod_perl in general, but from looking at use.perl it does indeed sound
> like Matt just figured this out 1)
I had just never realised it was a possible source of XSS bugs - mostly
because if I'm creating a cookie (which is the only time user passed data
might go in the headers) I'd use libapreq, which escapes the data anyway.
So it's not something I would normally do, but I found it intruiging that
it was possible.
Mostly what it comes down to for me is that AxKit already prevents other
XSS bugs (tag injection) by its nature of using XML, so I was looking for
an automated way to mitigate other ways of doing XSS. On my list I've got:
1. Tag injection. Check - AxKit prevents these.
2. Href javascript injection. Must be manually checked in the app.
3. Header \n\n injection. Only preventable in ap_send_header_field.
(if anyone knows any XSS bugs I've missed do shout)
> All this really boils down to is that the stuff that operates on
> r->headers_out and r->err_headers_out shouldn't allow for line endings
> to be in there, but directly putting input from the client in there is
> even worse IMHO.
I agree.
It's like you always check your code to make sure that it's well written
and does the right thing, but I still always turn on warnings and strict
:-)
> And I don't really think it's designed to output a header. Tables where
> used because it made it easy to implement (I assume), and it's only in
> mod_perl and not the C api that there are specific functions for adding
> to r->headers_out and r->err_headers_out, so ultimatively if anything
> should deal with it, it's either the mod_perl functions OR as Matt has
> submitted around line 1570 (in my non-up-to-date cvs copy) in
> http_protocol.c, and yes, I do believe it's the right thing to do so you
> can't output \n nor \r's in headers.
I'm not really sure it's possible to fix in mod_perl either. Otherwise I
would have done it there because I find it easier to maintain a patched
mod_perl than a patched Apache.
> And if you would have to bypass the header_out rule you would have to
> write to the socket yourself and somehow make sure apache doesn't send
> the headers, right? (I'm not so sure about this part :-))
Well, then you should be using AxKit ;-)
--
<!-- Matt -->
<:->get a SMart net</:->
Spam trap - do not mail: spam-sig@spamtrap.messagelabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Tue, Jan 28, 2003 at 01:08:28PM +0200, Issac Goldstand wrote:
> ----- Original Message -----
> From: "Thomas Eibner" <ei...@mnmailhost.bridge.com>
> Subject: Re: Mitigating XSS in the mod_perl API
>
>
> > On Mon, Jan 27, 2003 at 02:45:13PM +0000, Matt Sergeant wrote:
> > > On Mon, 27 Jan 2003, Thomas Eibner wrote:
> > >
> > > > So, because a programmer doesn't check the validity of the input he
> gets
> > > > it's a bug that should be fixed in Apache? Maybe someone should make
> > > > sure that the same thing can't happen with allowing CGI input going
> > > > straight into a form.. oh wait.
> > > > I don't see anyone from dev@httpd wanting to "fix" this bogus error
> when
> > > > it's really just doing what the programmer wants to do (when he is not
> > > > validating the input).
> > >
> > > The programmer wants to output a header. If he accidentally tries to
> > > output something thats not a header he actually ends up outputting body.
> > > Thats a bug.
> >
> > I can see the validity of your point, but it's still a programmer error.
> > The same thing could happen if you did this as plain CGI and outputted
> > something you weren't supposed to do.
>
> Right - except that if he's outputting it raw from CGI, we can assume that
> he knows what he's doing, while if he's using a function which is DESIGNED
> to output a header (which should NOT have an extra \n), that's obviously
> either a mistake or a malicious misuse. Neither of which warrants the
> function doing what it was asked to do. If the programmer wants to
> intentionally bypass the "header_out" rule, he should bypass some more and
> send the headers himself. I know that sounds weak, but I've got to say that
> I side with Matt here.
Yes, that sounds very weak. To me it sounds like Matt doesn't know what
he is doing if he's passing RAW input from a client directly into
something. I know it sounds harsh and I'm not trying to degrade Matt as
I have great respect for the work he is and has been doing for Perl and
mod_perl in general, but from looking at use.perl it does indeed sound
like Matt just figured this out 1)
All this really boils down to is that the stuff that operates on
r->headers_out and r->err_headers_out shouldn't allow for line endings
to be in there, but directly putting input from the client in there is
even worse IMHO.
And I don't really think it's designed to output a header. Tables where
used because it made it easy to implement (I assume), and it's only in
mod_perl and not the C api that there are specific functions for adding
to r->headers_out and r->err_headers_out, so ultimatively if anything
should deal with it, it's either the mod_perl functions OR as Matt has
submitted around line 1570 (in my non-up-to-date cvs copy) in
http_protocol.c, and yes, I do believe it's the right thing to do so you
can't output \n nor \r's in headers.
And if you would have to bypass the header_out rule you would have to
write to the socket yourself and somehow make sure apache doesn't send
the headers, right? (I'm not so sure about this part :-))
1) http://use.perl.org/~Matts/journal/10161
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Matt Sergeant wrote:
> Here's the patch in case anyone is interested in applying it to their own
> apache. I think there's probably a bug in that \n might not always be the
> right thing to look for (CRLF issues), so please send me corrections ;-)
I'm not a C guy, but there are some constants in httpd.h that may help with
CRLF portability stuff (see below).
and just for my interest, can you explain the continuation logic? I don't
get it :)
--Geoff
#ifndef CHARSET_EBCDIC
#define LF 10
#define CR 13
#define CRLF "\015\012"
#define OS_ASC(c) (c)
#else /* CHARSET_EBCDIC */
#include "ap_ebcdic.h"
/* OSD_POSIX uses the EBCDIC charset. The transition ASCII->EBCDIC is done in
* the buff package (bread/bputs/bwrite), so everywhere else, we use
* "native EBCDIC" CR and NL characters. These are therefore defined as
* '\r' and '\n'.
* NB: this is not the whole truth - sometimes \015 and \012 are contained
* in literal (EBCDIC!) strings, so these are not converted but passed.
*/
#define CR '\r'
#define LF '\n'
#define CRLF "\r\n"
#define OS_ASC(c) (os_toascii[c])
#endif /* CHARSET_EBCDIC */
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Tue, Jan 28, 2003 at 02:50:54PM +0000, Matt Sergeant wrote:
> For geoff...
>
> On Tue, 28 Jan 2003, Matt Sergeant wrote:
>
> > Index: src/main/http_protocol.c
> > ===================================================================
> > RCS file: /home/cvs/apache-1.3/src/main/http_protocol.c,v
> > retrieving revision 1.329
> > diff -u -r1.329 http_protocol.c
> > --- src/main/http_protocol.c 3 Oct 2002 20:51:53 -0000 1.329
> > +++ src/main/http_protocol.c 28 Jan 2003 11:26:37 -0000
> > @@ -1561,8 +1561,16 @@
> > const char *fieldname,
> > const char *fieldval)
> > {
> > + char *line_feed;
> > if (strcasecmp(fieldname, "ETag") == 0) {
> > if (ap_table_get(r->notes, "no-etag") != NULL) {
> > + return 1;
> > + }
> > + }
> > + if ((line_feed = strchr(fieldval, '\n')) != NULL) {
>
> If we find a line feed anywhere, the the line_feed variable points to the
> line feed character.
>
> Now headers in RFC terms can have continuations, which means something
> like:
>
> Refresh: 1;
> url=/foo
>
> So basically a continuation is CRLF WS+ ...
>
> So all we have to do is look for whitespace (space or horizontal tab)
> after the line feed. And that's at line_feed[1]. Anything else is invalid.
thanks for the explanation, I was wondering about it too.
> > + /* don't allow any headers with line feeds in them */
> > + if (line_feed[1] != ' ' && line_feed[1] != '\t') {
> > + /* unless it's a continuation */
> > return 1;
> > }
> > }
Would you consider what I was trying to do in my patch? To just not
discard the header line but rather just terminate when you discover
\n or \r (and not a continuation following).
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matt Sergeant <ma...@sergeant.org>.
Here's the patch in case anyone is interested in applying it to their own
apache. I think there's probably a bug in that \n might not always be the
right thing to look for (CRLF issues), so please send me corrections ;-)
I haven't actually run this, so it might not work. But to quote Lord
Flashheart: "That's the kind of guy I am". :-)
Index: src/main/http_protocol.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/http_protocol.c,v
retrieving revision 1.329
diff -u -r1.329 http_protocol.c
--- src/main/http_protocol.c 3 Oct 2002 20:51:53 -0000 1.329
+++ src/main/http_protocol.c 28 Jan 2003 11:26:37 -0000
@@ -1561,8 +1561,16 @@
const char *fieldname,
const char *fieldval)
{
+ char *line_feed;
if (strcasecmp(fieldname, "ETag") == 0) {
if (ap_table_get(r->notes, "no-etag") != NULL) {
+ return 1;
+ }
+ }
+ if ((line_feed = strchr(fieldval, '\n')) != NULL) {
+ /* don't allow any headers with line feeds in them */
+ if (line_feed[1] != ' ' && line_feed[1] != '\t') {
+ /* unless it's a continuation */
return 1;
}
}
--
<!-- Matt -->
<:->get a SMart net</:->
Spam trap - do not mail: spam-sig@spamtrap.messagelabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Issac Goldstand <ma...@beamartyr.net>.
----- Original Message -----
From: "Thomas Eibner" <ei...@mnmailhost.bridge.com>
Subject: Re: Mitigating XSS in the mod_perl API
> On Mon, Jan 27, 2003 at 02:45:13PM +0000, Matt Sergeant wrote:
> > On Mon, 27 Jan 2003, Thomas Eibner wrote:
> >
> > > So, because a programmer doesn't check the validity of the input he
gets
> > > it's a bug that should be fixed in Apache? Maybe someone should make
> > > sure that the same thing can't happen with allowing CGI input going
> > > straight into a form.. oh wait.
> > > I don't see anyone from dev@httpd wanting to "fix" this bogus error
when
> > > it's really just doing what the programmer wants to do (when he is not
> > > validating the input).
> >
> > The programmer wants to output a header. If he accidentally tries to
> > output something thats not a header he actually ends up outputting body.
> > Thats a bug.
>
> I can see the validity of your point, but it's still a programmer error.
> The same thing could happen if you did this as plain CGI and outputted
> something you weren't supposed to do.
Right - except that if he's outputting it raw from CGI, we can assume that
he knows what he's doing, while if he's using a function which is DESIGNED
to output a header (which should NOT have an extra \n), that's obviously
either a mistake or a malicious misuse. Neither of which warrants the
function doing what it was asked to do. If the programmer wants to
intentionally bypass the "header_out" rule, he should bypass some more and
send the headers himself. I know that sounds weak, but I've got to say that
I side with Matt here.
Issac
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matthew Byng-Maddick <mo...@lists.colondot.net>.
On Mon, Jan 27, 2003 at 08:57:38AM -0600, Thomas Eibner wrote:
> On Mon, Jan 27, 2003 at 02:45:13PM +0000, Matt Sergeant wrote:
> > The programmer wants to output a header. If he accidentally tries to
> > output something thats not a header he actually ends up outputting body.
> > Thats a bug.
> I can see the validity of your point, but it's still a programmer error.
Yes, but have you ever heard of the concept of defensive programming?
> The same thing could happen if you did this as plain CGI and outputted
> something you weren't supposed to do. We have full access to the API and
> can do whatever we want (both in Perl and C), that doesn't mean we should
> let our guards down. I still don't consider this a serious problem :)
If the API is for dealing with headers, and can output something that isn't
a header, I'd say that's a brokenness in the API. I agree that not
validating your input is a reason for deserving to lose, but on the other
hand, this is equally of the Apache API in this case.
My tuppence.
MBM
--
Matthew Byng-Maddick <mb...@colondot.net> http://colondot.net/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matt Sergeant <ma...@sergeant.org>.
On Mon, 27 Jan 2003, Thomas Eibner wrote:
>
> On Mon, Jan 27, 2003 at 02:45:13PM +0000, Matt Sergeant wrote:
> > On Mon, 27 Jan 2003, Thomas Eibner wrote:
> >
> > > So, because a programmer doesn't check the validity of the input he gets
> > > it's a bug that should be fixed in Apache? Maybe someone should make
> > > sure that the same thing can't happen with allowing CGI input going
> > > straight into a form.. oh wait.
> > > I don't see anyone from dev@httpd wanting to "fix" this bogus error when
> > > it's really just doing what the programmer wants to do (when he is not
> > > validating the input).
> >
> > The programmer wants to output a header. If he accidentally tries to
> > output something thats not a header he actually ends up outputting body.
> > Thats a bug.
>
> I can see the validity of your point, but it's still a programmer error.
> The same thing could happen if you did this as plain CGI and outputted
> something you weren't supposed to do. We have full access to the API and
> can do whatever we want (both in Perl and C), that doesn't mean we should
> let our guards down. I still don't consider this a serious problem :)
I guess it depends which school of thought you come from - that the
programmer is stupid for not having checks in every inch of his code, or
that if we can, and if it has little impact, then we should do some checks
to stop the programmer hurting himself.
Anyway the main reason for doing this is there's no other way. Since
headers_out is just a plain table object, and there are no "setter" hooks
for tables, so I couldn't do it in mod_perl space. And I couldn't do it in
AxKit space, so I had to patch Apache, which has a single exit point for
all headers. I find it quite disappointing that people don't support
fixing security issues here :-/
--
<!-- Matt -->
<:->get a SMart net</:->
Spam trap - do not mail: spam-sig@spamtrap.messagelabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Mon, Jan 27, 2003 at 02:45:13PM +0000, Matt Sergeant wrote:
> On Mon, 27 Jan 2003, Thomas Eibner wrote:
>
> > So, because a programmer doesn't check the validity of the input he gets
> > it's a bug that should be fixed in Apache? Maybe someone should make
> > sure that the same thing can't happen with allowing CGI input going
> > straight into a form.. oh wait.
> > I don't see anyone from dev@httpd wanting to "fix" this bogus error when
> > it's really just doing what the programmer wants to do (when he is not
> > validating the input).
>
> The programmer wants to output a header. If he accidentally tries to
> output something thats not a header he actually ends up outputting body.
> Thats a bug.
I can see the validity of your point, but it's still a programmer error.
The same thing could happen if you did this as plain CGI and outputted
something you weren't supposed to do. We have full access to the API and
can do whatever we want (both in Perl and C), that doesn't mean we should
let our guards down. I still don't consider this a serious problem :)
/Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>>I suppose the opposition is that well, mod_perl is just an API, and we
>>>shouldn't be forcing programming styles onto the programmer, but there
>>>isn't a single legitimate use of \n in an outgoing header, so I don't
>>>think that argument has much weight.
>>>
>>>Thoughts?
>>
>>If that causes a bug, may be this should be fixed in Apache?
>
>
> So, because a programmer doesn't check the validity of the input he gets
> it's a bug that should be fixed in Apache? Maybe someone should make
> sure that the same thing can't happen with allowing CGI input going
> straight into a form.. oh wait.
> I don't see anyone from dev@httpd wanting to "fix" this bogus error when
> it's really just doing what the programmer wants to do (when he is not
> validating the input). Tables should have the ability to store both \r
> and \n's IMHO.
>
I think both arguments carry some weight. yes, programmers should be
responsible for not validating data from clients and, in general, it's not
our problem to save them from bad programming practices.
however, for HTML-based data we give them utilities, and the problem is well
known. I can't remember the last time we told users to chomp variables they
put in the headers_out table :)
we could probably throw a warning if there are embedded newlines in the
string sent to headers_out() and err_headers_out(), but that seems like way
too much regex parsing. and I can't think of a better way than that since,
yes, tables should be allowed to hold any string.
I'd probably just vote to publicize the issue on the various lists and in
the guide, so it becomes rote when dealing with header setting.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matt Sergeant <ma...@sergeant.org>.
On Mon, 27 Jan 2003, Thomas Eibner wrote:
> So, because a programmer doesn't check the validity of the input he gets
> it's a bug that should be fixed in Apache? Maybe someone should make
> sure that the same thing can't happen with allowing CGI input going
> straight into a form.. oh wait.
> I don't see anyone from dev@httpd wanting to "fix" this bogus error when
> it's really just doing what the programmer wants to do (when he is not
> validating the input).
The programmer wants to output a header. If he accidentally tries to
output something thats not a header he actually ends up outputting body.
Thats a bug.
> Tables should have the ability to store both \r
> and \n's IMHO.
I never said otherwise. The patch I sent to dev@ only affects outgoing
headers. There is no legitimate use for allowing multiple line feeds in
headers.
Though I do realise now that my patch is wrong. It needs to check for \n
in the header value followed by something that isn't space or htab. I'll
fix that and re-send to the list.
--
<!-- Matt -->
<:->get a SMart net</:->
Spam trap - do not mail: spam-sig@spamtrap.messagelabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Thomas Eibner <ei...@mnmailhost.bridge.com>.
On Mon, Jan 27, 2003 at 09:28:38AM +1100, Stas Bekman wrote:
> Matt Sergeant wrote:
> >At the moment it's possible to do nasty XSS things in mod_perl when you
> >set a cookie. That's because $r->headers_out->add() (or set()) doesn't
> >care if you include carriage returns in your header. Simple example
> >would be:
> >
> >$r->headers_out->add('Set-Cookie' => 'mycookie=' . $r->param('myparam'));
> >
> >Just stick a couple of carriage returns in myparam and you can get the
> >result:
> >
> >Date: Sun, 26 Jan 2003 10:39:41 GMT
> >Server: Apache/1.3.26 (Unix) AxKit/1.6_01 mod_perl/1.27
> >Client-Date: Sun, 26 Jan 2003 10:39:42 GMT
> >Client-Response-Num: 1
> >Set-Cookie: mycookie=foo
> >
> ><javascript>
> >....
> ></javascript>
> >Connection: close
> >Transfer-Encoding: chunked
> >Content-Type: text/plain; charset=ISO-8859-1
> >
> >Thus giving you a full blown XSS bug.
> >
> >Now wouldn't it be simple to just ban \n's in headers_out()? Throw an
> >exception or something? It might be a bit tricky because headers_out is
> >just a plain Apache table, but there's probably a way.
> >
> >I suppose the opposition is that well, mod_perl is just an API, and we
> >shouldn't be forcing programming styles onto the programmer, but there
> >isn't a single legitimate use of \n in an outgoing header, so I don't
> >think that argument has much weight.
> >
> >Thoughts?
>
> If that causes a bug, may be this should be fixed in Apache?
So, because a programmer doesn't check the validity of the input he gets
it's a bug that should be fixed in Apache? Maybe someone should make
sure that the same thing can't happen with allowing CGI input going
straight into a form.. oh wait.
I don't see anyone from dev@httpd wanting to "fix" this bogus error when
it's really just doing what the programmer wants to do (when he is not
validating the input). Tables should have the ability to store both \r
and \n's IMHO.
/Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Stas Bekman <st...@stason.org>.
Matt Sergeant wrote:
> On Sunday, Jan 26, 2003, at 22:28 Europe/London, Stas Bekman wrote:
>
>>
>> If that causes a bug, may be this should be fixed in Apache?
>
>
> That sounds plausible. Perhaps you could bring this up on new-httpd@ for
> me since I'm not subscribed ;-)
You know that bringing up things on httpd-dev (it's not new-httpd anymore)
doesn't really work, as the httpd developers are busy scratching their
personal itches or having responsibilities. So, thanks, but not me.
> I guess the argument you could use is that if you write out a header
> with a few line feeds in it, you actually end up writing the body, which
> isn't what the API is for.
That's true. So now you have a good reason to subscribe to httpd-dev and have
this omission fixed ;)
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Matt Sergeant <ma...@sergeant.org>.
On Sunday, Jan 26, 2003, at 22:28 Europe/London, Stas Bekman wrote:
>
> If that causes a bug, may be this should be fixed in Apache?
That sounds plausible. Perhaps you could bring this up on new-httpd@
for me since I'm not subscribed ;-)
I guess the argument you could use is that if you write out a header
with a few line feeds in it, you actually end up writing the body,
which isn't what the API is for.
Matt.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: Mitigating XSS in the mod_perl API
Posted by Stas Bekman <st...@stason.org>.
Matt Sergeant wrote:
> At the moment it's possible to do nasty XSS things in mod_perl when you
> set a cookie. That's because $r->headers_out->add() (or set()) doesn't
> care if you include carriage returns in your header. Simple example
> would be:
>
> $r->headers_out->add('Set-Cookie' => 'mycookie=' . $r->param('myparam'));
>
> Just stick a couple of carriage returns in myparam and you can get the
> result:
>
> Date: Sun, 26 Jan 2003 10:39:41 GMT
> Server: Apache/1.3.26 (Unix) AxKit/1.6_01 mod_perl/1.27
> Client-Date: Sun, 26 Jan 2003 10:39:42 GMT
> Client-Response-Num: 1
> Set-Cookie: mycookie=foo
>
> <javascript>
> ....
> </javascript>
> Connection: close
> Transfer-Encoding: chunked
> Content-Type: text/plain; charset=ISO-8859-1
>
> Thus giving you a full blown XSS bug.
>
> Now wouldn't it be simple to just ban \n's in headers_out()? Throw an
> exception or something? It might be a bit tricky because headers_out is
> just a plain Apache table, but there's probably a way.
>
> I suppose the opposition is that well, mod_perl is just an API, and we
> shouldn't be forcing programming styles onto the programmer, but there
> isn't a single legitimate use of \n in an outgoing header, so I don't
> think that argument has much weight.
>
> Thoughts?
If that causes a bug, may be this should be fixed in Apache?
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org