7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQuery DataTablesを使うときのXSS対策

Posted at
var result = /* サーバーから取得したデータとか */

$("#dataTable").DataTable({
	data: result,
	columns: [
		{ data: "name" },
		{ data: "age" },
		{ data: "tel" },
		...
	]
});

なにも考えずにそのままデータを追加すると、サニタイズされないのでXSSが成立してしまう。

なので、ユーザーから入力されたものを含んだデータはrender$.fn.dataTable.render.text()を設定しておきましょう。

$("#dataTable").DataTable({
	data: result,
	columns: [
		{ data: "name", render: $.fn.dataTable.render.text() },
		{ data: "age",  render: $.fn.dataTable.render.text() },
		{ data: "tel",  render: $.fn.dataTable.render.text() },
		...
	]
});

参考

DataTables - Security

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?