Can malicious javascript code be injected through $()?

后端 未结 4 1059
青春惊慌失措
青春惊慌失措 2020-12-16 14:53

Example:

if($(\'#\' + untrusted_js_code).length) > 0
  ....`

Normally \"untrusted_js_code\" should be a simple string representing the I

4条回答
  •  一向
    一向 (楼主)
    2020-12-16 15:29

    Yes, if you're using an older version of jQuery, this is possible in certain cases. This was fixed (here's the commit) in version 1.6.3. Also see the corresponding bug report.

    The commit includes a test case that clarifies the issue:

    jQuery( '#' ).appendTo("#qunit-fixture");
    

    With jQuery versions prior to 1.6.3, the onerror code would have been executed.

    Your particular example (just checking for the length) doesn't have this issue, though.

提交回复
热议问题