php-general Digest 24 Sep 2013 10:38:18 -0000 Issue 8375

2013-09-24 Thread php-general-digest-help

php-general Digest 24 Sep 2013 10:38:18 - Issue 8375

Topics (messages 322160 through 322170):

Re: No MIME-Type in imap_fetch_overview()
322160 by: Negin Nickparsa
322161 by: Negin Nickparsa
322166 by: Aziz Saleh
322168 by: Domain nikha.org
322169 by: Domain nikha.org

Re: Apache
322162 by: Domain nikha.org
322165 by: Ashley Sheridan
322167 by: Tamara Temple
322170 by: Arno Kuhl

Re: filesize() fails on file and works on it's copy (same permissions, same 
directory)
322163 by: Michał Kochanowicz
322164 by: Michał Kochanowicz

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
I have read your mail twice and still I could not get what you want
exactly.  can't get the structure of the email either although you
elaborate it in details.

you have said something about human rights that I couldn't understand why?
but if you want to get the type of files fetch the structure and then you
can use disposition string, find the attachment and then return the
array.




Sincerely
Negin Nickparsa


On Wed, Sep 18, 2013 at 3:27 PM, Domain nikha.org m...@nikha.org wrote:

 Hello all,

 im posting this here, because the bug report system of php.net is not
 right
 place for my problem. It's not a bug, but a wish - an I found there no
 wishlist option at all.

 I'm running my own webmail-client, written in PHP. It is stable, fast and
 pretty, showing the full power of the PHP imap section.

 Of course it presents paginated content lists for every mailbox the user
 may
 open. These lists tell him some usefull things about every mail actually
 listed:
 Sender, date, subject, size and (eventually) flags.

 All these things are nicely delivered by the function
 imap_fetch_overview()
 The same could be done by calling imap_headerinfo() for every single
 mail, but
 fetch_overview seems to be faster, because it does it at once for the
 whole
 batch.

 BUT NONE OF THEM returns any information about the MIME-Type of the mail!

 Since the user of my webmail client has the intrinsic, natural born an
 general
 human right to KNOW whether some mail in his mailbox has attachments or
 not, I'm
 forced to do very ugly things. My script calls additionally for every (!)
 actually listed mail  imap_fetchbody($connect, $msg_no, 0) - where
 $connect
 holds the result of imap_open().

 That gives me the mail header, the script reads the line starting with
 Content-Type: and returns its content. Evaluating this against mixed or
 alternative we have finaly what we want: This mail has attachments! Or is
 written in HTML, what is even more we wanted!

 Works fine, but is ugly. First fetch_overview parses all mail headers,
 then
 they are fetched again to be parsed for the MIME-Type. I could just omit
 fetch_overview and read the headers by my own means, that whould be
 faster,
 but then I loose the size information, that is NOT (and cannot) be part of
 the
 mail header!

 If I want to have both, size and MIME-Type, and I WANT to have both,
 respecting
 the intrinsic, natural born and general human rights of my user, im must
 call
 both, overview and fetchbody.

 My question is this: Is there a better solution? Or is there someone that
 knows
 someone among the PHP-Developpers to suggest them an improvement of the
 functions imap_fetch_overivew() and imap_headerinfo(). Please, Please,
 add
 the MIME-Type to your fantastic object collections! BTW: It's really easy.
 Read
 the Content-Type-Line! Sorry...

 Hope, somebody has an idea,
 my regards,

 Niklaus









 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


---End Message---
---BeginMessage---
I have read your mail twice and still I could not get what you want
exactly.  can't get the structure of the email either although you
elaborate it in details.

you have said something about human rights that I couldn't understand why?
but if you want to get the type of files fetch the structure and then you
can use disposition string, find the attachment and then return the
array.




Sincerely
Negin Nickparsa


On Wed, Sep 18, 2013 at 3:27 PM, Domain nikha.org m...@nikha.org wrote:

 Hello all,

 im posting this here, because the bug report system of php.net is not
 right
 place for my problem. It's not a bug, but a wish - an I found there no
 wishlist option at all.

 I'm running my own webmail-client, written in PHP. It is stable, fast and
 pretty, showing the full power of the PHP imap section.

 Of course it presents paginated content lists for every mailbox the user
 may
 open. These lists tell him some usefull things about every mail actually
 listed:
 

php-general Digest 24 Sep 2013 22:58:33 -0000 Issue 8376

2013-09-24 Thread php-general-digest-help

php-general Digest 24 Sep 2013 22:58:33 - Issue 8376

Topics (messages 322171 through 322175):

Re: Apache
322171 by: Domain nikha.org
322172 by: Domain nikha.org
322173 by: Ashley Sheridan
322174 by: Domain nikha.org
322175 by: Ashley Sheridan

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Ashley Sheridan am Montag, 23. September 2013 - 21:35:

 No, no, no! That is not a good stand-in for fundamental security
 principles!
 
 This is a better method for ensuring an image is really an image:
 
 ?php
 if(isset($_FILES['file']))
 {
   list($width, $height) = getimagesize($_FILES['file']['tmp_name']);
   if($width  $height)
   {
   $source = imagecreatefromjpeg($_FILES['file']['tmp_name']);
   $dest = imagecreatetruecolor($width, $height);
   
   imagecopyresampled($dest, $source,
   0, 0, 0, 0,
   $width, $height, $width, $height);
   imagejpeg($dest, basename($_FILES['file']['tmp_name']));
   }
   else
   echo {$_FILES['file']['name']} is not a jpeg;
 }
 ?
 form enctype=multipart/form-data method=post
   input type=file name=file/
   input type=submit name=submit value=submit/
 /form
 
 Obviously it's only rough, and checks only for jpeg images, but
that's
 easy to alter. I've just tested this with a regular jpeg, the same
jpeg
 with PHP code concatenated onto the end (which still appears to be a
 valid image to viewing/editing software) and a pure PHP file with a
.jpg
 extension. In the case of the first 2, a new jpeg is generated with
the
 same image and without the code. The third example just echoes out an
 error.
 

Dear Ashley, nice, but useless for this problem!

First, because users may upload other things than images! PDF's, audio
files, videos etc! And on behalf images: GD you are using handles only
jpeg, gif and png. There are about hunderd other image types on the way,
users can upload! How to detect them, if the extension is missleading?

And even if we succeed: As your script demonstrates very well, malicious
code does not affect the rendering of the image. The hacker says: Hi,
this is a nice picture, play it, and then, please do this--follows his
code, that can be a desaster for the whole system.

Yes, your script seems to purge the image file, simply because GD does
not copy the malware code. But why are you sure about that? You cannot
see that code, OK, but may be it was executed in the plain GD
environement? What you are doing is dangerous, because you force the
execution of things that should be never executed!

no no no forget it. After all we cannot exclude that users come in
with malware. But we MUST exclude, it is executed on the web server.
That is the Apache chainsaw massacre as Steward whould say. And probably
it can be avoided by purging the filenames (not the files!). 

Nevertheless, the standard configuration of the Apache servers is
basically unacceptable. It must execute user requests and never ever
user files! Period.

Have nice days,
Niklaus 
---End Message---
---BeginMessage---
Tamara Temple am Montag, 23. September 2013 - 22:38:
 
 On Sep 23, 2013, at 1:36 PM, Domain nikha.org m...@nikha.org wrote:
 
  Better solutions?
 
 One I have used, and continue to use in Apache environments, is place
uploads only in a place where they cannot be executed by turning off
such options and handlers in that directory. This is *in addition* to
untainting files and names of uploaded files.

Good idea. I will do this right now

Niklaus
---End Message---
---BeginMessage---


Domain nikha.org m...@nikha.org wrote:
Ashley Sheridan am Montag, 23. September 2013 - 21:35:

 No, no, no! That is not a good stand-in for fundamental security
 principles!
 
 This is a better method for ensuring an image is really an image:
 
 ?php
 if(isset($_FILES['file']))
 {
  list($width, $height) = getimagesize($_FILES['file']['tmp_name']);
  if($width  $height)
  {
  $source = imagecreatefromjpeg($_FILES['file']['tmp_name']);
  $dest = imagecreatetruecolor($width, $height);
  
  imagecopyresampled($dest, $source,
  0, 0, 0, 0,
  $width, $height, $width, $height);
  imagejpeg($dest, basename($_FILES['file']['tmp_name']));
  }
  else
  echo {$_FILES['file']['name']} is not a jpeg;
 }
 ?
 form enctype=multipart/form-data method=post
  input type=file name=file/
  input type=submit name=submit value=submit/
 /form
 
 Obviously it's only rough, and checks only for jpeg images, but
that's
 easy to alter. I've just tested this