Skip to content
KitploitKITPLOIT
ツールエクスプロイトブログ
Log in
提出
ツールエクスプロイトブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

フィードお問い合わせプライバシー© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
js-xss — ホワイトリストで指定された設定を用いて、信頼できないHTMLをサニタイズする(XSSを防止) | Kitploit
ツール/GitHubGitHub/leizongmin/js-xss
防御ツールウェブアプリケーション悪用ウェブセキュリティユーティリティとフレームワーク
GitHubleizongmin/js-xss

js-xss

ホワイトリストで指定された設定を用いて、信頼できないHTMLをサニタイズする(XSSを防止)

リポジトリを見る
5.3k6302026年10月24日Kitploit レビュー済み
共有
ウェブサイト

NPM version Node.js CI Test coverage David deps node version npm download npm license

ホワイトリストで指定した設定を用いて、信頼できない HTML をサニタイズする(XSS を防止)。

Greenkeeper badge

xss


xss は、XSS 攻撃を防ぐためにユーザーからの入力をフィルタリングするために使用されるモジュールです。 (XSS 攻撃とは何か?)

プロジェクトホームページ: http://jsxss.com

オンラインで試す: http://jsxss.com/en/try.html

中文版文档


機能

  • ホワイトリストで許可される HTML タグとその属性を指定する
  • カスタム関数を使用して任意のタグや属性を処理する

参考資料

  • XSS Filter Evasion Cheat Sheet
  • Data URI scheme
  • XSS with Data URI Scheme

ベンチマーク(参考値)

  • xss モジュール: 22.53 MB/s
  • モジュール [email protected] の xss() 関数: 6.9 MB/s

テストコードについては benchmark ディレクトリを参照してください。

xss モジュールを利用しているプロジェクト

  • nodeclub - MongoDB を使用した Node.js 製 BBS - https://github.com/cnodejs/nodeclub
  • cnpmjs.org - 企業向けのプライベート npm レジストリおよびウェブ - https://github.com/cnpm/cnpmjs.org
  • cocalc.com - 共同計算とデータサイエンス - https://cocalc.com

インストール

NPM

npm install xss

Bower

bower install xss

または

bower install https://github.com/leizongmin/js-xss.git

使用方法

Node.js の場合

var xss = require("xss");
var html = xss('<script>alert("xss");</script>');
console.log(html);

サニタイズ済みHTMLと削除された要素を取得する

filterXSSWithResult を使用すると、サニタイズ済みのHTMLと削除されたタグ/属性のリストの両方を取得できます:

var xss = require("xss");
var result = xss.filterXSSWithResult('<script>alert("xss");</script><a href="#" onclick="evil()">click</a>');
console.log(result.html);
// Output: "&lt;script&gt;alert(\"xss\");&lt;/script&gt;<a href=\"#\">click</a>"
console.log(result.removed);
// Output: [
//   { type: "tag", tag: "script", html: "<script>", isClosing: false },
//   { type: "tag", tag: "script", html: "</script>", isClosing: true },
//   { type: "attr", tag: "a", attr: "onclick", value: "evil()" }
// ]

ブラウザ上で

Shim モード(参照ファイル test/test.html):

<script src="https://rawgit.com/leizongmin/js-xss/master/dist/xss.js"></script>
<script>
  // apply function filterXSS in the same way
  var html = filterXSS('<script>alert("xss");</scr' + "ipt>");
  alert(html);
</script>

AMDモード - shim:

<script>
  require.config({
    baseUrl: "./",
    paths: {
      xss: "https://rawgit.com/leizongmin/js-xss/master/dist/xss.js",
    },
    shim: {
      xss: { exports: "filterXSS" },
    },
  });
  require(["xss"], function (xss) {
    var html = xss('<script>alert("xss");</scr' + "ipt>");
    alert(html);
  });
</script>

注意: 本番環境では URL https://rawgit.com/leizongmin/js-xss/master/dist/xss.js を使用しないでください。

コマンドラインツール

ファイルの処理

xss コマンドラインツールを使用してファイルを処理できます。使用方法:

xss -i <input_file> -o <output_file>

例:

xss -i origin.html -o target.html

アクティブテスト

次のコマンドを実行すると、コマンドラインで HTML コードを入力し、フィルタリングされた出力を確認できます:

xss -t

詳細については、$ xss -h を実行して確認してください。

カスタムフィルタールール

xss() 関数を使用する場合、第2引数でカスタムルールを指定できます:

options = {}; // Custom rules
html = xss('<script>alert("xss");</script>', options);

毎回 options を渡すのを避けるために、FilterXSS インスタンスを作成するという、より迅速な方法を取ることもできます:

options = {}; // Custom rules
myxss = new xss.FilterXSS(options);
// then apply myxss.process()
html = myxss.process('<script>alert("xss");</script>');

options のパラメータの詳細は以下で説明します。

ホワイトリスト

whiteList を指定することで、例えば { 'tagName': [ 'attr-1', 'attr-2' ] } のようにします。ホワイトリストに含まれないタグや属性はフィルタリングされます。例えば:

// only tag a and its attributes href, title, target are allowed
var options = {
  whiteList: {
    a: ["href", "title", "target"],
  },
};
// With the configuration specified above, the following HTML:
// <a href="#" onclick="hello()"><i>Hello</i></a>
// would become:
// <a href="#">&lt;i&gt;Hello&lt;/i&gt;</a>

デフォルトのホワイトリストについては、xss.whiteList を参照してください。

allowList もサポートされており、whiteList と同じ機能を持ちます。

マッチしたタグに対するハンドラ関数のカスタマイズ

onTag でハンドラ関数を指定することにより:

function onTag(tag, html, options) {
  // tag is the name of current tag, e.g. 'a' for tag <a>
  // html is the HTML of this tag, e.g. '<a>' for tag <a>
  // options is some addition informations:
  //   isWhite    boolean, whether the tag is in whitelist
  //   isClosing  boolean, whether the tag is a closing tag, e.g. true for </a>
  //   position        integer, the position of the tag in output result
  //   sourcePosition  integer, the position of the tag in input HTML source
  // If a string is returned, the current tag would be replaced with the string
  // If return nothing, the default measure would be taken:
  //   If in whitelist: filter attributes using onTagAttr, as described below
  //   If not in whitelist: handle by onIgnoreTag, as described below
}

一致したタグの属性に対するハンドラ関数のカスタマイズ

onTagAttr でハンドラ関数を指定することにより:

function onTagAttr(tag, name, value, isWhiteAttr) {
  // tag is the name of current tag, e.g. 'a' for tag <a>
  // name is the name of current attribute, e.g. 'href' for href="#"
  // isWhiteAttr whether the attribute is in whitelist
  // If a string is returned, the attribute would be replaced with the string
  // If return nothing, the default measure would be taken:
  //   If in whitelist: filter the value using safeAttrValue as described below
  //   If not in whitelist: handle by onIgnoreTagAttr, as described below
}

ホワイトリストにないタグのハンドラ関数をカスタマイズする

ハンドラ関数を onIgnoreTag で指定することにより:

function onIgnoreTag(tag, html, options) {
  // Parameters are the same with onTag
  // If a string is returned, the tag would be replaced with the string
  // If return nothing, the default measure would be taken (specifies using
  // escape, as described below)
}

ホワイトリストにない属性に対するハンドラ関数のカスタマイズ

onIgnoreTagAttr でハンドラ関数を指定することにより:

function onIgnoreTagAttr(tag, name, value, isWhiteAttr) {
  // Parameters are the same with onTagAttr
  // If a string is returned, the value would be replaced with this string
  // If return nothing, then keep default (remove the attribute)
}

HTML 用エスケープ関数のカスタマイズ

escapeHtml でハンドラ関数を指定します。以下はデフォルトの 関数です (変更は推奨されません):

function escapeHtml(html) {
  return html.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

属性値のエスケープ関数をカスタマイズする

デフォルトの safeAttrValue は、カスタムホワイトリストでこれらの属性が許可されている場合、action と formaction もチェックします。フォームの送信先には HTTP(S) または相対 URL(パス、クエリ、フラグメントを含む)を使用できます。javascript: や data: を含むその他のスキームは拒否されます。href と src に対する data:image/ の例外は、フォームの送信先には適用されません。

ハンドラ関数を safeAttrValue で指定することにより:

ツールをダウンロード

関連ツール

  • wazuh

    オープンソースのXDRおよびSIEMプラットフォーム。脅威検出、ログ分析、ファイル整合性監視、脆弱性評価、コンプライアンス管理をエンドポイントおよびクラウドワークロード全体で実現します。

  • suricata

    リアルタイムのトラフィック検査、侵入検知・防御、プロトコル解析、およびルールベースの脅威ハンティングのためのオープンソースのネットワーク IDS/IPS/NSM エンジン。

  • zeek

    Zeekは、あなたが知っている典型的なIDSとは大きく異なる、強力なネットワーク分析フレームワークです。

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

  • 1

    Callisto

    jetp1ane/callisto

    Ghidraを介して実行可能ファイルを逆コンパイルし、Semgrepで擬似Cコードをスキャンし、GPT-3.5-Turboを使用して検出結果を検証することで誤検知を低減する、自動化されたバイナリ脆弱性解析ツール。

    2.2k
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock ワンタップ実行アプリ(CVE-2026-43499)

    841
  • 3

    DFRoot

    a2333c/dfroot

    Samsung Galaxy S25 Ultra (SM-S938B) 向けの Android root ツール。DirtyFrag CVE-2026-43284 と CVE-2026-43499 を連鎖させ、KernelSU 経由で起動時に自動的に root を取得します。

    446
  • 4

    ARTEX

    baarai/artex

    プランナー/ワーカーエージェント、資産グラフと探索グラフ、MITMトラフィック記録、脆弱性の再テストを備えたLLMマルチエージェント自律ペネトレーションテストプラットフォーム。

    386
  • 5

    OsintHunter

    letox4/osinthunter

    🎯 究極のOSINTツールキット:調査グラフ、信頼度スコアリング、エイリアスファミリー、マップ、タイムライン、レポート。49個のモジュール、400以上のサイト、APIキー不要。

    350
  • 6

    faraday

    infobyte/faraday

    オープンソースかつAIを活用したサイバーセキュリティツール。オフェンシブセキュリティ、脆弱性管理、自律型ペネトレーションテスト向け。ラテンアメリカのハッカーによって開発され、世界中で使用されています。

    333

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →