daily-share icon indicating copy to clipboard operation
daily-share copied to clipboard

网络安全 (2023-01-18)

Open yaogengzhu opened this issue 2 years ago • 2 comments

应对前端html的一些不安全注入

可用的第三方库 dompurify

const createDOMPurify = require('dompurify');
const { JSDOM } = require('jsdom');

const window = new JSDOM('').window;
const DOMPurify = createDOMPurify(window);
const clean = DOMPurify.sanitize('<b>hello there</b>');
DOMPurify.sanitize('<img src=x onerror=alert(1)//>'); // becomes <img src="x">
DOMPurify.sanitize('<svg><g/onload=alert(2)//<p>'); // becomes <svg><g></g></svg>
DOMPurify.sanitize('<p>abc<iframe//src=jAva&Tab;script:alert(3)>def</p>'); // becomes <p>abc</p>
DOMPurify.sanitize('<math><mi//xlink:href="data:x,<script>alert(4)</script>">'); // becomes <math><mi></mi></math>
DOMPurify.sanitize('<TABLE><tr><td>HELLO</tr></TABL>'); // becomes <table><tbody><tr><td>HELLO</td></tr></tbody></table>
DOMPurify.sanitize('<UL><li><A HREF=//google.com>click</UL>'); // becomes <ul><li><a href="//google.com">click</a></li></ul>

yaogengzhu avatar Jan 18 '23 03:01 yaogengzhu

SQL注入防范 举例中: mysql中的一些介绍

文档不错, 值得一看

var userId = 'some user provided value';
var sql    = 'SELECT * FROM users WHERE id = ' + connection.escape(userId);
connection.query(sql, function (error, results, fields) {
  if (error) throw error;
  // ...
});

yaogengzhu avatar Jan 18 '23 07:01 yaogengzhu

sql防注入用参数,不拼接

BarlowDu avatar Jan 31 '23 09:01 BarlowDu