sanitizeName not applied to names inside stopNodes (quote injection / tag break-out bypass)
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- security
調査の方向性
The unsanitized names come from buildRawContent() and buildAttributesForStopNode() in fxb.js, and from getRawContent(), attr_to_str_raw() and attr_to_str() in orderedJs2Xml.js. Start by reading how resolveName() is used on the regular path, then route the stopNode paths through it. Done means the three reproduction payloads come out sanitized in both build modes, with regression tests. The issue says PR #33 already implements this, so check that PR before starting.
索引モデルが issue の本文から書いたものです。
説明
Description
When a sanitizeName callback is configured, it is applied to tag and attribute names on the regular build path — but not inside stopNodes. This affects both build modes:
fxb.js(plain-object mode):buildRawContent()andbuildAttributesForStopNode()write names to the output without routing them throughresolveName().orderedJs2Xml.js(preserveOrdermode):getRawContent()andattr_to_str_raw()do the same, andattr_to_str()explicitly skips name sanitization whenisStopNodeis true.
Reproduction
const { XMLBuilder } = require("fast-xml-builder");
const builder = new XMLBuilder({
ignoreAttributes: false,
sanitizeName: (n) => n.replace(/[^\w.:-]/g, '_'), // per docs
stopNodes: ["root.raw"],
});
// 1. Quote injection in an attribute name forges a new attribute:
builder.build({ root: { raw: { '#text': 'content', '@_x" onmouseover="alert(1)': 'y' } } });
// <root><raw x" onmouseover="alert(1)="y">content</raw></root>
// 2. '>' in a tag name breaks out of the tag
builder.build({ root: { raw: { 'a href="javascript:x"': 'v' } } });
// <root><raw><a href="javascript:x">v</a href="javascript:x"></raw></root>
// 3. preserveOrder mode is also affected
builder.build([{ root: [{ raw: [{ '#text': 'x' }, { 'a onclick="alert(1)': [{ '#text': 'y' }] }] }] }]);
// <root><raw>x<a onclick="alert(1)">y</a onclick="alert(1)"></raw></root>
The same payload on a non-stopNode path is sanitized correctly (a_href__javascript_x_), so this is an inconsistent bypass of the sanitizeName security control (CWE-74: Special Element Injection) rather than missing-by-design behavior — sanitizeName was introduced in 1.2.0 specifically to guard against injection via invalid XML names.
Impact
Any application that sets both sanitizeName and stopNodes gets no name sanitization for everything inside the stopNode subtree: quotes in attribute names can forge additional attributes, and > can close a tag early, changing document structure for downstream consumers. Round-tripping through the parser yields a structure that differs from what was built, so this can also cause silent data-integrity problems.
Suggested fix
Route both paths through the existing resolveName() helper (pass matcher and qNameValidator down from arrToStr/processTextOrObjNode). PR #33 implements this fix plus regression tests for both build modes.
- 主要言語
- JavaScript
- スター
- 22
- フォーク
- 9
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NaturalIntelligence/fast-xml-builder のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
-
`preserveOrder: true` with `format: true` formats mixed content wrongly and adds whitespace to content that ends with `>`対応中かも @neumaennl が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
`XMLBuilder` object should be exported as a named export, not just the type対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
NaturalIntelligence/fast-xml-builder#25 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 54/100
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
NaturalIntelligence/fast-xml-builder#4 · コメント 5 件 · リアクション 2 件 ·
NaturalIntelligence/fast-xml-builder の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
-
Extended search drops any query term that contains a line break対応中かも @goranai が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
area:mcp
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信