mirror of
				https://github.com/Mibew/java.git
				synced 2025-10-31 02:26:00 +03:00 
			
		
		
		
	enable act=del url check for auth tokens for csrf attacks
Conflicts: src/messenger/webim/view/agents.php
This commit is contained in:
		
							parent
							
								
									5e75270cd0
								
							
						
					
					
						commit
						423c1335f4
					
				| @ -767,17 +767,22 @@ function jspath() | |||||||
| 
 | 
 | ||||||
| /* authorization token check for CSRF attack */ | /* authorization token check for CSRF attack */ | ||||||
| function csrfchecktoken(){ | function csrfchecktoken(){ | ||||||
|  |   /* if auth token not set, set it now */ | ||||||
|   if(!isset($_SESSION['csrf_token'])){ |   if(!isset($_SESSION['csrf_token'])){ | ||||||
|       $_SESSION['csrf_token']=sha1(rand(10000000,99999999)); |       $_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"); |   // check the turing code for post requests and del requests
 | ||||||
|       } |   if ($_SERVER['REQUEST_METHOD'] == 'POST'){ | ||||||
|  |     //if token match
 | ||||||
|  |     if(!isset($_POST['csrf_token']) || ($_POST['csrf_token'] != $_SESSION['csrf_token'])){ | ||||||
|  | 
 | ||||||
|  |       die("CSRF failure"); | ||||||
|     } |     } | ||||||
|  |   } else if($_GET['act'] == 'del' && $_GET['csrf_token'] != $_SESSION['csrf_token']){ | ||||||
|  |        | ||||||
|  |     die("CSRF failure"); | ||||||
|  |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* print csrf token as a hidden field*/ | /* print csrf token as a hidden field*/ | ||||||
| @ -785,4 +790,9 @@ function print_csrf_token_input(){ | |||||||
|   echo "<input name='csrf_token' type='hidden' value='".$_SESSION['csrf_token']."' />"; |   echo "<input name='csrf_token' type='hidden' value='".$_SESSION['csrf_token']."' />"; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /* print csrf token in url format */ | ||||||
|  | function print_csrf_token_in_url(){ | ||||||
|  |   echo "&csrf_token=".$_SESSION['csrf_token']; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| ?>
 | ?>
 | ||||||
|  | |||||||
| @ -22,6 +22,8 @@ | |||||||
| require_once('../libs/common.php'); | require_once('../libs/common.php'); | ||||||
| require_once('../libs/operator.php'); | require_once('../libs/operator.php'); | ||||||
| 
 | 
 | ||||||
|  | csrfchecktoken(); | ||||||
|  | 
 | ||||||
| $operator = check_login(); | $operator = check_login(); | ||||||
| force_password($operator); | force_password($operator); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -120,7 +120,7 @@ require_once('inc_errors.php'); | |||||||
| <?php } ?>
 | <?php } ?>
 | ||||||
| 	</td> | 	</td> | ||||||
| 	<td> | 	<td> | ||||||
| 		<a class="removelink" id="i<?php echo $a['operatorid'] ?>" href="<?php echo $webimroot ?>/operator/operators.php?act=del&id=<?php echo $a['operatorid'] ?>"> | 		<a class="removelink" id="i<?php echo $a['operatorid'] ?>" href="<?php echo $webimroot ?>/operator/operators.php?act=del&id=<?php echo $a['operatorid'] ?><?php print_csrf_token_in_url() ?>"> | ||||||
| 			<?php echo getlocal("remove.item") ?>
 | 			<?php echo getlocal("remove.item") ?>
 | ||||||
| 		</a> | 		</a> | ||||||
| 	</td> | 	</td> | ||||||
| @ -140,4 +140,4 @@ $('a.removelink').click(function(){ | |||||||
| } /* content */ | } /* content */ | ||||||
| 
 | 
 | ||||||
| require_once('inc_main.php'); | require_once('inc_main.php'); | ||||||
| ?>
 | ?>
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user