Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-20-2007, 6:33 PM   #11
Good Man
 
Good Man's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

shimmyshack <matt.farey@gmail.com> wrote in
news:1179166417.178718.236160@y80g2000hsf.googlegr oups.com:

>> > Though it would likely be much easier if you were to strip out all
>> > characters except alpha, numeric, and the underscore prior to
>> > storage (file and database entry). Perhaps replace spaces with
>> > underscores.

>>
>> I agree. Here's what I use to "clean" the filenames of all uploaded
>> files:
>>
>> function cleanFile ($filename) { //clean up the file name



> the trouble with this kind of blacklist banning is that it allows
> encoding and otherforms of clever attack.
> better to use a whitelist.


How would you use a 'whitelist' in this case? By only allowing filenames
with alphanumeric characters? If that were the case, that would require
forcing your user to rename their files before upload... time-intensive and
annoying...

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 05-20-2007, 6:33 PM   #12
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On May 14, 7:41 pm, Good Man <h...@letsgo.com> wrote:
> shimmyshack <matt.fa...@gmail.com> wrote innews:1179166417.178718.236160@y80g2000hsf.google groups.com:
>
> >> > Though it would likely be much easier if you were to strip out all
> >> > characters except alpha, numeric, and the underscore prior to
> >> > storage (file and database entry). Perhaps replace spaces with
> >> > underscores.

>
> >> I agree. Here's what I use to "clean" the filenames of all uploaded
> >> files:

>
> >> function cleanFile ($filename) { //clean up the file name

> > the trouble with this kind of blacklist banning is that it allows
> > encoding and otherforms of clever attack.
> > better to use a whitelist.

>
> How would you use a 'whitelist' in this case? By only allowing filenames
> with alphanumeric characters? If that were the case, that would require
> forcing your user to rename their files before upload... time-intensive and
> annoying...


no just use the kind of oneliner specified earlier in this post using
eregi_replace, or preg_replace, no requirement on the user, and you
can allow any utf8 character you think is reasonable without allowing
attacks and without banning characters like comma (,) apostraphe (')
and space ( ) which are all legitimate chars for a filesystem and
should really be allowed if the OS supports them.
Perhaps you can explain this line:
$filename = str_replace("","",$filename);
and then check out sql, command, xss and other injection attacks and
why blacklisting doesnt work, here for example is OWASPs good practise
advice (for sql injection prevention):
"Use vigorous white-list style checking on any user input"
the same goes for any user input.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 05-20-2007, 6:33 PM   #13
Good Man
 
Good Man's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

shimmyshack <matt.farey@gmail.com> wrote in
news:1179168720.073863.12650@y80g2000hsf.googlegro ups.com:


>> >> function cleanFile ($filename) { //clean up the file name

>>
>> > the trouble with this kind of blacklist banning is that it allows
>> > encoding and otherforms of clever attack.
>> > better to use a whitelist.

>>
>> How would you use a 'whitelist' in this case? By only allowing
>> filenames with alphanumeric characters? If that were the case, that
>> would require forcing your user to rename their files before
>> upload... time-intensive and annoying...

>
> no just use the kind of oneliner specified earlier in this post using
> eregi_replace, or preg_replace, no requirement on the user, and you
> can allow any utf8 character you think is reasonable without allowing
> attacks and without banning characters like comma (,) apostraphe (')
> and space ( ) which are all legitimate chars for a filesystem and
> should really be allowed if the OS supports them.


** eregi from earlier post **
$strName = eregi_replace("([^a-zA-Z_\-])",'',$_FILES['userfile']
['name']);
**

just to make sure I follow... your eregi function keeps any of your
'allowed' characters in your expression, and replaces everything else
with just a "" (blank), is that correct?


> Perhaps you can explain this line:
> $filename = str_replace("","",$filename);


bad code!


> and then check out sql, command, xss and other injection attacks and
> why blacklisting doesnt work


i actually only use 'blacklisting' for my file uploads. perhaps i will
revisit that issue.

thanks.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 05-20-2007, 6:33 PM   #14
Mark Goodge
 
Mark Goodge's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On Mon, 14 May 2007 00:25:58 +0200, Alfred Molon put finger to
keyboard and typed:

>In article <1179093340.453709.241100@n59g2000hsh.googlegroups .com>,
>matt.farey@gmail.com says...
>
>> alfred, i use php uploads with single quotes just fine, it copes with
>> a large range of characters including single quotes.
>> you say "the uploads dont work properly" but I am unclear as to what
>> that means, where does the process fail? I just think it's a coding/
>> config issue, the actual upload functionality will remain completely
>> unaffected - if your system is set up properly.

>
>It's a shared host and I can not set the system.
>
>In any case what happens, is that the image will upload and be stored in
>the temporary , but then the PHP code will mess up the filename.
>
>For instance, if I upload the file "Al Azhar's mosque Cairo.jpg" (with
>the apostrophe), the PHP code will automatically convert the filename to
>"Al Azhar\'s mosque Cairo.jpg" (i.e. insert a backslash) and store a
>file named "Al Azhar\'s mosque Cairo.jpg" in the temporary directory.


You've got magic_quotes_gpc switched on, but the script assumes you
haven't. That's one of the gotchas I was referring to in a different
thread!

There are two solutions to that. The easiest, if you can do it, is to
switch it off either sitewide (using .htaccess) or in the upload
script (using php_ini_set()). If you can't, then you need to pass the
variables through stripslashes() before processing them with your file
handling routine.

Mark
--
Please give me one! http://www.pleasegivemeone.com
"L'amore giunger, l'amore"
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 05-20-2007, 6:33 PM   #15
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

On May 14, 8:03 pm, Good Man <h...@letsgo.com> wrote:
> shimmyshack <matt.fa...@gmail.com> wrote innews:1179168720.073863.12650@y80g2000hsf.googleg roups.com:
>
>
>
> >> >> function cleanFile ($filename) { //clean up the file name

>
> >> > the trouble with this kind of blacklist banning is that it allows
> >> > encoding and otherforms of clever attack.
> >> > better to use a whitelist.

>
> >> How would you use a 'whitelist' in this case? By only allowing
> >> filenames with alphanumeric characters? If that were the case, that
> >> would require forcing your user to rename their files before
> >> upload... time-intensive and annoying...

>
> > no just use the kind of oneliner specified earlier in this post using
> > eregi_replace, or preg_replace, no requirement on the user, and you
> > can allow any utf8 character you think is reasonable without allowing
> > attacks and without banning characters like comma (,) apostraphe (')
> > and space ( ) which are all legitimate chars for a filesystem and
> > should really be allowed if the OS supports them.

>
> ** eregi from earlier post **
> $strName = eregi_replace("([^a-zA-Z_\-])",'',$_FILES['userfile']
> ['name']);
> **
>
> just to make sure I follow... your eregi function keeps any of your
> 'allowed' characters in your expression, and replaces everything else
> with just a "" (blank), is that correct?
>
> > Perhaps you can explain this line:
> > $filename = str_replace("","",$filename);

>
> bad code!
>
> > and then check out sql, command, xss and other injection attacks and
> > why blacklisting doesnt work

>
> i actually only use 'blacklisting' for my file uploads. perhaps i will
> revisit that issue.
>
> thanks.


yes that eregi just allows the char range, but you can specify others
including accented chars and so on, it does as you say and replaces
any others, so
Go0od man->Goodman
(as spaces arent allowed in the above ereg)
preg_replace is generally preferred by works in a similar way.
You can also make things more user friendly, say a user has to enter a
britsih postcode (which has many rules for its formation) and the user
types
P014 instead of PO14 (zero instead of capital letter O) or doesnt use
a space.
P0145QL
you can write a simple reg exp that filters chars and checks for
comformity to rules, and makes likely replacements (like 0 and O)
where there is no abiguity interpreting the users input, and throw out
the result to the lookup.
I love 'em!

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 05-20-2007, 6:33 PM   #16
Good Man
 
Good Man's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

shimmyshack <matt.farey@gmail.com> wrote in
news:1179172003.349086.263840@e51g2000hsg.googlegr oups.com:


>> just to make sure I follow... your eregi function keeps any of your
>> 'allowed' characters in your expression, and replaces everything else
>> with just a "" (blank), is that correct?

>
> yes that eregi just allows the char range, but you can specify others
> including accented chars and so on, it does as you say and replaces
> any others, so
> Go0od man->Goodman
> (as spaces arent allowed in the above ereg)
> preg_replace is generally preferred by works in a similar way.
> You can also make things more user friendly, say a user has to enter a
> britsih postcode (which has many rules for its formation) and the user
> types
> P014 instead of PO14 (zero instead of capital letter O) or doesnt use
> a space.
> P0145QL
> you can write a simple reg exp that filters chars and checks for
> comformity to rules, and makes likely replacements (like 0 and O)
> where there is no abiguity interpreting the users input, and throw out
> the result to the lookup.
> I love 'em!



Thanks for the discussion, that will be my future method for 'cleaning'
filenames and the like.

Best,
GM
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 05-20-2007, 6:33 PM   #17
Alfred Molon
 
Alfred Molon's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Uploading files with an apostrophe in the filename

In article <8gch43lufh9e3u7cdg1nqnbmoi798svu38@news.markshous e.net>, usenet@listmail.good-stuff.co.uk says...

> There are two solutions to that. The easiest, if you can do it, is to
> switch it off either sitewide (using .htaccess) or in the upload
> script (using php_ini_set()). If you can't, then you need to pass the
> variables through stripslashes() before processing them with your file
> handling routine.


Well, in the end I changed the user interface. Now there is a file
selection window and a separate picture name field. The filename can be
anything (it is just ignored). The picture name text field is processed
with preg_replace to ensure that only the specified characters are in
it.
--

Alfred Molon
http://www.molon.de - Photos of Asia, Africa and Europe
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading by FTP and line ending settings dorayme PHP 1 05-20-2007 6:33 PM
Uploading files with IXR (XMLRPC) soraya_soch@yahoo.com PHP 0 05-20-2007 6:33 PM
Uploading files with IXR (XMLRPC) soraya_soch@yahoo.com PHP 0 05-20-2007 6:33 PM
bin & cue files , spot516 Computer Consoles 1 05-08-2007 5:55 AM
Does anyone know how to make .dll files? Mattster Windows 8 04-05-2006 1:25 AM


Featured Websites




All times are GMT +1. The time now is 11:48 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98