[英]Php-MySql Security approach while INSERT’ing INTO MySql & fetching from MySql to screen
我想我在stackoverflow.com上讀到“如果您需要轉義或類似的操作,請及時進行操作”,因此在驗證頁面中我會驗證用戶輸入(是否為空檢查,長度檢查和結構檢查(例如:郵件結構,自定義標簽結構);我使用$_POST['']
變量作為輸入。在驗證過程中,即使在自定義錯誤打印部件中,我的錯誤消息中也不包含任何$_POST['']
值文本。
作為臨時說明:在php-mysql交互過程中,我使用准備好的語句和參數化的查詢 。 輸入是否經過驗證; 在插入INTO MySql之前,我將標簽從輸入中剝離,因為我不允許除自定義結構化標簽之外的任何html標簽。 (例如**bold text** === <strong>bold text</strong>
),然后將用戶輸入插入MySql db。
我只應用htmlspecialchars()命令從MySql db打印到屏幕
我不確定自己。 我的方法是否有明顯或隱藏的弱點? 在此先感謝php gurus的寶貴意見。 BR
在插入MySql db的過程中,我不會剝離標簽。 由於某些原因,請參閱下面的ÁlvaroG.Vicario的注釋。 BR。
到目前為止,討論的主題是如何避免SQL注入和持久性跨站點腳本。 聽起來您在正確的軌道上。
the escape syntax for the part of the HTML document you're putting untrusted data into.
”。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="tr">
<head>
<title>trial</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="tr" />
<meta name="Description" content="trial page." />
<meta name="Robots" content="noindex, nofollow" />
</head>
<body>
<?php
$str1 = '<script>alert(\'inside of input with quote\')</script>';
$str2 = '<script>alert("inside of input with quote")</script>';
$str3 = "<script>alert(\"inside of input with quote\")</script>";
$str4 = '<script>alert("outside of form")</script>';
?>
<form method="post" action="">
<fieldset>
<legend>alert attempts inside form inputs</legend>
<label for="input1">label 1:</label><br />
<input type="text" value="<?php echo htmlspecialchars($str1) ; ?>" name="input1" id="input1" /><br /><br />
<legend>attempt 2</legend>
<label for="input2">label 2:</label><br />
<input type="text" value="<?php echo htmlspecialchars($str2) ; ?>" name="input2" id="input2" /><br /><br />
<label for="input3">Label 3:</label><br />
<input type="text" value="<?php echo htmlspecialchars($str3) ; ?>" name="input3" id="input3" />
</fieldset>
</form>
<?php echo htmlspecialchars($str4) ; ?>
</body>
</html>
strip_tags()
這樣的額外工作將破壞用戶確切關心的鍵入內容,就像htmlspecialchars()
或htmlentities()
一樣。 htmlspecialchars()
以便用戶不會打擾的內容不會中斷,並且可能的惡意特殊字符將轉換為相應的HTML實體
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.