mirror of
				https://github.com/Mibew/java.git
				synced 2025-10-31 18:41:09 +03:00 
			
		
		
		
	having token checks on POST forms
This commit is contained in:
		
							parent
							
								
									1ab3efb86f
								
							
						
					
					
						commit
						b84b439358
					
				| @ -688,4 +688,24 @@ function jspath() | ||||
| 	return "js/$jsver"; | ||||
| } | ||||
| 
 | ||||
| ?>
 | ||||
| /* authorization token check for CSRF attack */ | ||||
| function csrfchecktoken(){ | ||||
|   if(!isset($_SESSION['csrf_token'])){ | ||||
|       $_SESSION['csrf_token']=sha1(rand(10000000,99999999)); | ||||
|     } | ||||
| 		// check the turing code
 | ||||
|     if ($_SERVER['REQUEST_METHOD'] == 'POST'){ | ||||
|       //if token match
 | ||||
|       if(!isset($_POST['csrf_token']) || ($_POST['csrf_token'] != $_SESSION['csrf_token'])){ | ||||
| 
 | ||||
|         die("CSRF failure"); | ||||
|       } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /* print csrf token as a hidden field*/ | ||||
| function print_csrf_token_input(){ | ||||
|   echo "<input name='csrf_token' type='hidden' value='".$_SESSION['csrf_token']."' />"; | ||||
| } | ||||
| 
 | ||||
| ?>
 | ||||
|  | ||||
| @ -44,4 +44,4 @@ function setup_operator_settings_tabs($opId, $active) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| ?>
 | ||||
| ?>
 | ||||
|  | ||||
| @ -23,6 +23,8 @@ require_once('../libs/common.php'); | ||||
| require_once('../libs/operator.php'); | ||||
| require_once('../libs/pagination.php'); | ||||
| 
 | ||||
| csrfchecktoken(); | ||||
| 
 | ||||
| function load_message($key) | ||||
| { | ||||
| 	global $mysqlprefix; | ||||
| @ -101,4 +103,4 @@ prepare_menu($operator, false); | ||||
| start_html_output(); | ||||
| require('../view/cannededit.php'); | ||||
| exit; | ||||
| ?>
 | ||||
| ?>
 | ||||
|  | ||||
| @ -23,6 +23,8 @@ require_once('../libs/common.php'); | ||||
| require_once('../libs/operator.php'); | ||||
| require_once('../libs/operator_settings.php'); | ||||
| 
 | ||||
| csrfchecktoken(); | ||||
| 
 | ||||
| $operator = check_login(); | ||||
| 
 | ||||
| $page = array('opid' => ''); | ||||
|  | ||||
| @ -23,6 +23,8 @@ require_once('../libs/common.php'); | ||||
| require_once('../libs/operator.php'); | ||||
| require_once('../libs/settings.php'); | ||||
| 
 | ||||
| csrfchecktoken(); | ||||
| 
 | ||||
| $operator = check_login(); | ||||
| 
 | ||||
| $page = array('agentId' => ''); | ||||
| @ -104,4 +106,4 @@ prepare_menu($operator); | ||||
| setup_settings_tabs(0); | ||||
| start_html_output(); | ||||
| require('../view/settings.php'); | ||||
| ?>
 | ||||
| ?>
 | ||||
|  | ||||
| @ -50,6 +50,10 @@ require_once('inc_errors.php'); | ||||
| 
 | ||||
| <?php if( $page['opid'] || $page['canmodify'] ) { ?>
 | ||||
| <form name="agentForm" method="post" action="<?php echo $webimroot ?>/operator/operator.php"> | ||||
| 
 | ||||
| <!-- add auth token --> | ||||
| <?php print_csrf_token_input() ?>
 | ||||
| 
 | ||||
| <input type="hidden" name="opid" value="<?php echo $page['opid'] ?>"/> | ||||
| 	<div> | ||||
| <?php if(!$page['needChangePassword']) { print_tabbar(); } ?>
 | ||||
| @ -130,4 +134,4 @@ require_once('inc_errors.php'); | ||||
| } /* content */ | ||||
| 
 | ||||
| require_once('inc_main.php'); | ||||
| ?>
 | ||||
| ?>
 | ||||
|  | ||||
| @ -44,6 +44,10 @@ require_once('inc_errors.php'); | ||||
| ?>
 | ||||
| 
 | ||||
| <form name="cannedForm" method="post" action="<?php echo $webimroot ?>/operator/cannededit.php"> | ||||
| 
 | ||||
| <!-- add auth token --> | ||||
| <?php print_csrf_token_input() ?>
 | ||||
| 
 | ||||
| <input type="hidden" name="key" value="<?php echo $page['key'] ?>"/> | ||||
| <?php if(!$page['key']) { ?>
 | ||||
| <input type="hidden" name="lang" value="<?php echo $page['locale'] ?>"/> | ||||
| @ -73,4 +77,4 @@ require_once('inc_errors.php'); | ||||
| } /* content */ | ||||
| 
 | ||||
| require_once('inc_main.php'); | ||||
| ?>
 | ||||
| ?>
 | ||||
|  | ||||
| @ -40,6 +40,9 @@ require_once('inc_errors.php'); | ||||
| 
 | ||||
| <form name="settings" method="post" action="<?php echo $webimroot ?>/operator/settings.php"> | ||||
| 
 | ||||
| <!-- add auth token --> | ||||
| <?php print_csrf_token_input() ?>
 | ||||
| 
 | ||||
| 	<div> | ||||
| <?php print_tabbar(); ?>
 | ||||
| 	<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner"> | ||||
| @ -155,4 +158,4 @@ require_once('inc_errors.php'); | ||||
| } /* content */ | ||||
| 
 | ||||
| require_once('inc_main.php'); | ||||
| ?>
 | ||||
| ?>
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user