View Issue Details

IDProjectCategoryView StatusLast Update
0007842mantisbtbugtrackerpublic2007-12-21 23:16
Reporteratomoid Assigned Togiallu  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.0.6 
Target Version1.1.0Fixed in Version1.1.0a4 
Summary0007842: File attachment permissions
Description

Currently, the permissions settings for file attachments is set to "0400".

This results in non-admin users of the webserver not being able to back up their file attachments since apparently some 'cant-copy-this' bit is set by the '0400' setting.

Workaround:
In core/file_api.php (at line 600) change "0400" to "0775"

  • This appears to fix the problem, at least it does in my limited tests on WindowsXP in as far as removing the 'read-only' attribute.

however, being a unix noob, i really dont know have a solid concept of what these numbers actually mean, or really what the appropriate setting really should be.

TagsNo tags attached.
Attached Files
permissions.patch (559 bytes)   
Index: file_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/file_api.php,v
retrieving revision 1.76
diff -u -r1.76 file_api.php
--- file_api.php	15 Sep 2006 05:02:47 -0000	1.76
+++ file_api.php	22 Mar 2007 08:18:38 -0000
@@ -644,7 +644,7 @@
 					if ( !move_uploaded_file( $p_tmp_file, $t_disk_file_name ) ) {
 					    trigger_error( FILE_MOVE_FAILED, ERROR );
 					}
-					chmod( $t_disk_file_name, 0400 );
+					chmod( $t_disk_file_name, 0644 );
 
 					$c_content = '';
 				} else {
permissions.patch (559 bytes)   
file-permissions.patch (2,166 bytes)   
Index: mantisbt/config_defaults_inc.php
===================================================================
--- mantisbt.orig/config_defaults_inc.php
+++ mantisbt/config_defaults_inc.php
@@ -760,6 +760,10 @@
 	# DISK, DATABASE, or FTP.
 	$g_file_upload_method	= DATABASE;
 
+	# When using FTP or DISK for storing uploaded files, they will be created
+	# with the following permissions
+	$g_new_file_permissions = 0400;
+
 	# FTP settings, used if $g_file_upload_method = FTP
 	$g_file_upload_ftp_server	= 'ftp.myserver.com';
 	$g_file_upload_ftp_user		= 'readwriteuser';
@@ -1798,4 +1802,6 @@
 
 	# access level required to run reports
 	$g_time_tracking_reporting_threshold = MANAGER;
+
+# vim: noexpandtab tabstop=4 softtabstop=0:
 ?>
Index: mantisbt/core/bug_api.php
===================================================================
--- mantisbt.orig/core/bug_api.php
+++ mantisbt/core/bug_api.php
@@ -595,7 +595,7 @@
 				$t_new_file_name = file_get_display_name( $t_bug_file['filename'] );
 				if ( ( config_get( 'file_upload_method' ) == DISK ) ) {
 					copy( $t_bug_file['diskfile'], $t_new_diskfile_name );
-					chmod( $t_new_diskfile_name, 0400 ); # make file read only in the file system
+					chmod( $t_new_diskfile_name, $g_new_file_permissions );
 				}
 
 				$query = "INSERT INTO $t_mantis_bug_file_table
Index: mantisbt/core/file_api.php
===================================================================
--- mantisbt.orig/core/file_api.php
+++ mantisbt/core/file_api.php
@@ -636,7 +636,7 @@
 					    trigger_error( FILE_MOVE_FAILED, ERROR );
 					}
 
-					chmod( $t_disk_file_name, 0644 );
+					chmod( $t_disk_file_name, $g_new_file_permissions );
 
 					$c_content = '';
 				} else {
Index: mantisbt/proj_doc_update.php
===================================================================
--- mantisbt.orig/proj_doc_update.php
+++ mantisbt/proj_doc_update.php
@@ -107,7 +107,7 @@
 				if ( !move_uploaded_file( $v_tmp_name, $t_disk_file_name ) ) {
 					trigger_error( FILE_MOVE_FAILED, ERROR );
 				}
-				chmod( $t_disk_file_name, 0400 );
+				chmod( $t_disk_file_name, $g_new_file_permissions );
 
 				$c_content = '';
 				break;
file-permissions.patch (2,166 bytes)   
file-permissionsv2.patch (2,126 bytes)   
Index: mantisbt/config_defaults_inc.php
===================================================================
--- mantisbt.orig/config_defaults_inc.php
+++ mantisbt/config_defaults_inc.php
@@ -760,6 +760,10 @@
 	# DISK, DATABASE, or FTP.
 	$g_file_upload_method	= DATABASE;
 
+	# When using FTP or DISK for storing uploaded files, they will be created
+	# on the server with the following permissions
+	$g_attachments_file_permissions = 0400;
+
 	# FTP settings, used if $g_file_upload_method = FTP
 	$g_file_upload_ftp_server	= 'ftp.myserver.com';
 	$g_file_upload_ftp_user		= 'readwriteuser';
Index: mantisbt/core/bug_api.php
===================================================================
--- mantisbt.orig/core/bug_api.php
+++ mantisbt/core/bug_api.php
@@ -595,7 +595,7 @@
 				$t_new_file_name = file_get_display_name( $t_bug_file['filename'] );
 				if ( ( config_get( 'file_upload_method' ) == DISK ) ) {
 					copy( $t_bug_file['diskfile'], $t_new_diskfile_name );
-					chmod( $t_new_diskfile_name, 0400 ); # make file read only in the file system
+					chmod( $t_new_diskfile_name, config_get( 'attachments_file_permissions' ) );
 				}
 
 				$query = "INSERT INTO $t_mantis_bug_file_table
Index: mantisbt/core/file_api.php
===================================================================
--- mantisbt.orig/core/file_api.php
+++ mantisbt/core/file_api.php
@@ -645,7 +645,7 @@ document.getElementById( span ).style.di
 					    trigger_error( FILE_MOVE_FAILED, ERROR );
 					}
 
-					chmod( $t_disk_file_name, 0644 );
+					chmod( $t_disk_file_name, config_get( 'attachments_file_permissions' ) );
 
 					$c_content = '';
 				} else {
Index: mantisbt/proj_doc_update.php
===================================================================
--- mantisbt.orig/proj_doc_update.php
+++ mantisbt/proj_doc_update.php
@@ -107,7 +107,7 @@
 				if ( !move_uploaded_file( $v_tmp_name, $t_disk_file_name ) ) {
 					trigger_error( FILE_MOVE_FAILED, ERROR );
 				}
-				chmod( $t_disk_file_name, 0400 );
+				chmod( $t_disk_file_name, config_get( 'attachments_file_permissions' ) );
 
 				$c_content = '';
 				break;
file-permissionsv2.patch (2,126 bytes)   

Activities

giallu

giallu

2007-03-21 05:00

reporter   ~0014222

Crash course in *nix permissions :) each file in the filesystem has basically:

  1. a owner user id (uid)
  2. a owner group id (gid)
  3. three bits for read/write/execute permissions for uid (1 on, 0 off)
  4. three bits for read/write/execute permissions for gid
  5. three bits for read/write/execute permissions for anyone else

So, 400 means the file can be read only by the owner: that looks like too tight...

on the other side 775 is too loose as it would be readable/writable by everyone

I think a saner value could be 644 (everyone can read, ownly the owner can write)

could you please verify if using 644 still fixes your problem?

atomoid

atomoid

2007-03-21 13:05

reporter   ~0014223

Last edited: 2007-03-21 13:21

i tried using "0644" in line 578 (previously i said line 600, which was only because i had spliced in swf file format support) in core/file_api.php resulting in:
chmod( $t_disk_file_name, 0644 );

tested it on our live Mantis installation running on a bonafide unix server

and the resultant 'rights' of the newly uploaded file on the server are "rw-r--r--"
and i can copy it to my local drive now and verified the file integrity is intact.

sound right?
works great for me now, so thanks a lot!
thanks for the crash course as well! it helped, but not that i yet understand how the sequence of 4 numbers (although ive only see three of the four digits ever used beyond zero) hooks up by number with the series of 9 char switches; so i'll have to look that one up some day. thanks again!

giallu

giallu

2007-03-22 03:19

reporter   ~0014226

glad to know it worked. I am attaching a patch for someone with access to CVS to commit.

Try this to complete your understanding about file permissions:
http://www.perlfect.com/articles/chmod.shtml

thraxisp

thraxisp

2007-03-29 20:29

reporter   ~0014282

This patch does create a security hole, however. Any user that can log into the system can now view attachments.

I'd suggest reverting this patch and running the web server backup as root, or the apache user.

giallu

giallu

2007-04-01 18:26

reporter   ~0014294

Reopening to address thraxisp concerns

giallu

giallu

2007-04-01 18:29

reporter   ~0014295

I uploaded a new patch which adds a new configuration parameter, so the user can select permissions for new files.

The default value is 0400 as before, so I think it will be also acceptable from the security POV

vboctor

vboctor

2007-04-10 23:12

manager   ~0014330

Following are my review comments for the patch:

  1. Rename $g_new_file_permissions to $g_attachments_file_permissions.
  2. Clarify that in the case of FTP, the copy on the web server will be the one that gets the permissions.
  3. When accessing the configuration option use config_get( 'attachments_file_permissions' );
  4. Remove "vim" tag.
giallu

giallu

2007-04-12 04:05

reporter   ~0014337

  1. Done
  2. I refined the comment mentioning "on the server"
  3. Done
  4. Done, but I hope you will consider adding that on every file to help vim users in following your coding style
giallu

giallu

2007-06-08 11:47

reporter   ~0014713

patch applied

Related Changesets

MantisBT: master ebf9e99e

2007-06-08 11:42

giallu


Details Diff
Fix 7842: File attachment permissions

git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@4377 <a class="text" href="/?p=mantisbt.git;a=object;h=f5dc347c">f5dc347c</a>-c33d-0410-90a0-b07cc1902cb9
Affected Issues
0007842
mod - config_defaults_inc.php Diff File
mod - proj_doc_update.php Diff File
mod - core/file_api.php Diff File
mod - core/bug_api.php Diff File