PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Simple security question
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Simple security question

Réponse
 
LinkBack Outils de la discussion
Vieux 01/03/2008, 16h02   #1
Mason Barge
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Simple security question

I am writing a page that lets people write a bulletin board message by
filling in a short form. The information is uploaded to a mysql database
and then displayed on the "Bulletin Board" page by reading the db.

1. What characters, if any, should I disallow other than html tag marks (<
and >)?
2. Do I need to inspect/filter the field contents on download as well as
upload?
3. Do I need to remove alternate codes for illegal symbols, especially tags
(e.g., "& lt;")?

The page is XHTML 1.0 Strict, charset=ISO-8859-1; the database field is
collated in latin1_swedish_ci.

In case it is not clear, the user types into a textarea, e.g. (example is
much simplified):

Lost: Jack Russell terrier. Answers to "supper". Strong jaws and teeth.
Able to jump on kitchen counters. If found, please give him a good home.

This is put through regex (which currently filters only < and >) then
uploaded to the db in the field 'text'. There is a "Bulletin Board" page
that queries the db, changes the field name to variables, and display it:

print "<div class='content'><h3>$head</h3><p>$text</p></div>";





--
Mason Barge

  Réponse avec citation
Vieux 01/03/2008, 16h51   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Simple security question

On Sat, 01 Mar 2008 17:02:40 +0100, Mason Barge <masonbarge@comcast.net>
wrote:

> I am writing a page that lets people write a bulletin board message by
> filling in a short form. The information is uploaded to a mysql
> database and then displayed on the "Bulletin Board" page by reading the
> db.
>
> 1. What characters, if any, should I disallow other than html tag marks
> (< and >)?
> 2. Do I need to inspect/filter the field contents on download as well as
> upload?
> 3. Do I need to remove alternate codes for illegal symbols, especially
> tags (e.g., "& lt;")?
>
> The page is XHTML 1.0 Strict, charset=ISO-8859-1; the database fieldis
> collated in latin1_swedish_ci.
>
> In case it is not clear, the user types into a textarea, e.g. (example
> is much simplified):
>
> Lost: Jack Russell terrier. Answers to "supper". Strong jaws and teeth.
> Able to jump on kitchen counters. If found, please give him a good home.
>
> This is put through regex (which currently filters only < and >) then
> uploaded to the db in the field 'text'. There is a "Bulletin Board"
> page that queries the db, changes the field name to variables, and
> display it:
>
> print "<div class='content'><h3>$head</h3><p>$text</p></div>";


Aither user strip_tags(), or just htmlspecialcharacters(). I usually just
employ the latter one, if someone want to look foolish by uploading HTML,
fine, it will be displayed as text, no big deal.
--
Rik Wasmus
  Réponse avec citation
Vieux 01/03/2008, 18h09   #3
Mason Barge
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Simple security question


"Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
newsp.t7cjrbxe5bnjuv@metallium.lan...
On Sat, 01 Mar 2008 17:02:40 +0100, Mason Barge <masonbarge@comcast.net>
wrote:

> I am writing a page that lets people write a bulletin board message by
> filling in a short form. The information is uploaded to a mysql database
> and then displayed on the "Bulletin Board" page by reading the db.
>
> 1. What characters, if any, should I disallow other than html tag marks
> (< and >)?
> 2. Do I need to inspect/filter the field contents on download as well as
> upload?
> 3. Do I need to remove alternate codes for illegal symbols, especially
> tags (e.g., "& lt;")?
>
> The page is XHTML 1.0 Strict, charset=ISO-8859-1; the database field is
> collated in latin1_swedish_ci.
>
> In case it is not clear, the user types into a textarea, e.g. (example is
> much simplified):
>
> Lost: Jack Russell terrier. Answers to "supper". Strong jaws and teeth.
> Able to jump on kitchen counters. If found, please give him a good home.
>
> This is put through regex (which currently filters only < and >) then
> uploaded to the db in the field 'text'. There is a "Bulletin Board" page
> that queries the db, changes the field name to variables, and display it:
>
> print "<div class='content'><h3>$head</h3><p>$text</p></div>";

-----------------------------
Either user strip_tags(), or just htmlspecialcharacters(). I usually just
employ the latter one, if someone want to look foolish by uploading HTML,
fine, it will be displayed as text, no big deal.
------------------------------
Thanks for the response. I'd rather just throw an error on html tags,
considering my audience, purpose, etc.

What I really am worried about is whether I need to be concerned with
characters other than tags.

  Réponse avec citation
Vieux 01/03/2008, 20h11   #4
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Simple security question

..oO(Mason Barge)

>What I really am worried about is whether I need to be concerned with
>characters other than tags.


No. Just make sure you properly escape your data when it goes into the
DB (use mysql_real_escape_string() or prepared statements) and when you
print it out again (htmlspecialchars()). These are the most important
things.

Micha
  Réponse avec citation
Vieux 05/03/2008, 04h59   #5
AnrDaemon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Simple security question

Greetings, Mason Barge.
In reply to Your message dated Saturday, March 1, 2008, 19:02:40,

> I am writing a page that lets people write a bulletin board message by
> filling in a short form. The information is uploaded to a mysql database
> and then displayed on the "Bulletin Board" page by reading the db.


> 1. What characters, if any, should I disallow other than html tag marks (<

and >>)?

Anything You decide to.

> 2. Do I need to inspect/filter the field contents on download as well as
> upload?


You should take care of user data in two, and only two places.

1. Before inserting into DB - apply proper escaping function like
mysql_escape_string()
2. Before showing data to the user - apply HTML special characters conversion
function htmlspecialchars().

Do not do anything else unless You for sure know what You doing (like BBcode
parsing)
Do NOT apply htmlspecialchars before inserting into DB. Common mistake - You
applying htmlspecialchars before DB insertion, then applying it again before
showing to the user - and now You absolutely can't use <>"'& symbols in text
fields.

> 3. Do I need to remove alternate codes for illegal symbols, especially tags
> (e.g., "& lt;")?


No, unless You know that user client sending codes that way (EVE Minibrowser
does that for example).

> The page is XHTML 1.0 Strict, charset=ISO-8859-1; the database field is
> collated in latin1_swedish_ci.


Doesn't matter, but I suggest to change Your database to use UTF-8.
Will save You from big headache later.


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h18.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 1,08327 seconds with 13 queries