in reply to Tag-Stripper is Insecure

Hi - super naive question here. How about:
$foo =~ s/</&lt;/g;
Instead of stripping the tags, just 'disable' them.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Tag-Stripper is Insecure
by japhy (Canon) on Feb 01, 2002 at 16:47 UTC
    Not to belittle your idea, but "duh". The best course of action is not to strip the tags, but to merely render them as actual text. You do need to s/>/&gt;/g too, or else I'll find a way to terminate a comment early or something wacky like that.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

(tye)Re: Tag-Stripper is Insecure
by tye (Sage) on Feb 01, 2002 at 16:41 UTC

    jeffa++, I think this is a good idea for lots of reasons beyond fixing this particular problem.

            - tye (but my friends call me "Tye")
Re: (jeffa) Re: Tag-Stripper is Insecure
by Matts (Deacon) on Feb 01, 2002 at 23:38 UTC
    Note that this does not fix everything. For example some older browsers actually saw \x8b and \x9b as < and > respectively, and rendered HTML tags if you used these characters. This is covered in CERT's XSS Vulnerability document.

    Luckily it's hard to find a browser vulnerable to this any more. But it's still something to watch for when trying to catch XSS vulnerabilities (the important thing here is to send the character set (encoding) along with the content-type header).

    Also it's naive at best to suggest just allowing text. Most systems want to accept some form of HTML. The thing to do is make sure you do allowed tags, not disallowed tags. And never allow attributes. That's just asking for trouble.

Re: (jeffa) Re: Tag-Stripper is Insecure
by mpeppler (Vicar) on Feb 01, 2002 at 19:22 UTC
    I've used that technique a lot when we didn't want message posters to be allowed to use any html tags at all.

    Michael