Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e679a1c

Browse files
committedSep 5, 2011
Fix #13191: Prevent further XSS issues relating to PHP_SELF
Silvia Alvarez (Debian package manager for MantisBT) has performed additional testing of patch d00745f and discovered that the XSS problems surrounding the use of $_SERVER['PHP_SELF'] have not been fully fixed. The form_action_self() function also used $_SERVER['PHP_SELF'] (retrieving the basename() component of the file name). Callees of this function did not escape this file name prior to printing it in the 'action' attribute of <form> elements. This patch swaps out PHP_SELF for SCRIPT_NAME (much safer as end users have no control over the value) and also applies escaping to the 'action' attribute of relevant <form> elements. Refer to Debian bug report #640297 [1] and dicussion on the mantisbt-dev mailing list for further details. Thank you Sils for the detailed analysis of the problem, detailed report, proposed solutions and extensive testing of patches for the latest round of vulnerabilities discovered. [1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=640297
1 parent cb74408 commit e679a1c

8 files changed

+9
-8
lines changed
 

‎billing_inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
# CSRF protection not required here - form does not result in modifications
7676
?>
7777

78-
<form method="post" action="<?php echo form_action_self() ?>">
78+
<form method="post" action="<?php echo string_attribute( form_action_self() ) ?>">
7979
<input type="hidden" name="id" value="<?php echo isset( $f_bug_id ) ? $f_bug_id : 0 ?>" />
8080
<table border="0" class="width100" cellspacing="0">
8181
<tr>

‎bugnote_stats_inc.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
# CSRF protection not required here - form does not result in modifications
6666
?>
6767

68-
<form method="post" action="<?php echo form_action_self() . '#bugnotestats' ?>">
68+
<form method="post" action="<?php echo string_attribute( form_action_self() . '#bugnotestats' ) ?>">
6969
<input type="hidden" name="id" value="<?php echo $f_bug_id ?>" />
7070
<table border=0 class="width100" cellspacing="0">
7171
<tr>

‎core/authentication_api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ function auth_reauthenticate_page( $p_user_id, $p_username ) {
694694
}
695695
?>
696696
</p>
697-
<form name="reauth_form" method="post" action="<?php echo form_action_self();?>">
697+
<form name="reauth_form" method="post" action="<?php echo string_attribute( form_action_self() ) ?>">
698698
<?php
699699
# CSRF protection not required here - user needs to enter password
700700
# (confirmation step) before the form is accepted.

‎core/form_api.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
* @return string Form action value
3636
*/
3737
function form_action_self() {
38-
return basename($_SERVER['PHP_SELF']);
38+
$t_self = trim( str_replace( "\0", '', $_SERVER['SCRIPT_NAME'] ) );
39+
return basename( $t_self );
3940
}
4041

4142
/**

‎core/helper_api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function helper_ensure_confirmed( $p_message, $p_button_label ) {
299299
print_hr();
300300
echo "\n$p_message\n";
301301

302-
echo '<form method="post" action="' . form_action_self() . "\">\n";
302+
echo '<form method="post" action="' . string_attribute( form_action_self() ) . "\">\n";
303303
# CSRF protection not required here - user needs to confirm action
304304
# before the form is accepted.
305305
print_hidden_inputs( gpc_strip_slashes( $_POST ) );

‎manage_config_email_page.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function get_section_end_for_email() {
286286
echo form_security_field( 'manage_config_revert' );
287287
echo "<input name=\"revert\" type=\"hidden\" value=\"notify_flags,default_notify_flags\"></input>";
288288
echo "<input name=\"project\" type=\"hidden\" value=\"$t_project\"></input>";
289-
echo "<input name=\"return\" type=\"hidden\" value=\"" . form_action_self() ."\"></input>";
289+
echo "<input name=\"return\" type=\"hidden\" value=\"" . string_attribute( form_action_self() ) ."\"></input>";
290290
echo "<input type=\"submit\" class=\"button\" value=\"";
291291
if ( ALL_PROJECTS == $t_project ) {
292292
echo lang_get( 'revert_to_system' );

‎manage_config_work_threshold_page.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function get_section_end() {
326326
echo form_security_field( 'manage_config_revert' );
327327
echo "<input name=\"revert\" type=\"hidden\" value=\"" . implode( ',', $t_overrides ) . "\"></input>";
328328
echo "<input name=\"project\" type=\"hidden\" value=\"$t_project_id\"></input>";
329-
echo "<input name=\"return\" type=\"hidden\" value=\"" . form_action_self() ."\"></input>";
329+
echo "<input name=\"return\" type=\"hidden\" value=\"" . string_attribute( form_action_self() ) ."\"></input>";
330330
echo "<input type=\"submit\" class=\"button\" value=\"";
331331
if ( ALL_PROJECTS == $t_project_id ) {
332332
echo lang_get( 'revert_to_system' );

‎manage_config_workflow_page.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ function access_row() {
477477
echo form_security_field( 'manage_config_revert' );
478478
echo "<input name=\"revert\" type=\"hidden\" value=\"" . implode( ',', $t_overrides ) . "\"></input>";
479479
echo "<input name=\"project\" type=\"hidden\" value=\"$t_project\"></input>";
480-
echo "<input name=\"return\" type=\"hidden\" value=\"" . form_action_self() ."\"></input>";
480+
echo "<input name=\"return\" type=\"hidden\" value=\"" . string_attribute( form_action_self() ) ."\"></input>";
481481
echo "<input type=\"submit\" class=\"button\" value=\"";
482482
if ( ALL_PROJECTS == $t_project ) {
483483
echo lang_get( 'revert_to_system' );

0 commit comments

Comments
 (0)
Please sign in to comment.