简体   繁体   English

通过放置 HTMLSPECIALCHARS() function 来避免 XSS 漏洞

[英]avoiding XSS vulnerability by putting HTMLSPECIALCHARS() function

hallo every body: I checked my website for security issues (vulnerabilities).大家好:我检查了我的网站是否存在安全问题(漏洞)。 the report said that there is a XSS vulnerability, in my login.php page in fact i try to fix this problem by putting the htmlspecialchars() in a variable that send to my database, but i am not sure if this is correct报告说在我的 login.php 页面中有一个 XSS 漏洞实际上我尝试通过将 htmlspecialchars() 放入发送到我的数据库的变量中来解决这个问题,但我不确定这是否正确

here is my PHP code for login.php page:这是我用于登录的 PHP 代码。php 页面:

<?php require_once('../Connections/minisrty.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['user'])) {
  **htmlspecialchars($loginUsername=$_POST['user'],ENT_QUOTES,'utf-8');**
  **htmlspecialchars($password=$_POST['pass'],ENT_QUOTES,'utf-8');**
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "insertion.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_minisrty, $minisrty);

  $LoginRS__query=sprintf("SELECT username, password FROM log WHERE username='%s' AND password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 

  $LoginRS = mysql_query($LoginRS__query, $minisrty) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";

    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

will this work..???这会工作..???

$filtered_variable = htmlspecialchars($bad_variable, ENT_QUOTES);

And you should use mysql_real_escape_string() on variables that are being put in a SQL query to avoid SQL injections.并且您应该对正在放入 SQL 查询的变量使用mysql_real_escape_string()以避免 SQL 注入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM