Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

JavaScript DOM XSS via fetch().json() → insertAdjacentHTML not detected by CodeQL

未關閉
#21,257 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
javascript
領域
security

研究方向

從 JavaScript security-extended 查詢套件開始,檢視 fetch().json() 回應和 insertAdjacentHTML 的建模方式。判斷此流程是否被刻意排除,或是需要對來源和接收點進行建模,接著根據提供的範例驗證結論,並確認是否預期會得到 XSS 結果。

由索引模型根據 Issue 內容生成。

描述

Description of the false positive

We are trying to better understand the design decisions behind JavaScript XSS detection in CodeQL, specifically around taint sources involving network responses.

I have a piece of client-side JavaScript that builds HTML using insertAdjacentHTML with values coming from a fetch().json() response. From an application-security perspective, this is treated as a potential DOM XSS risk in our project, but CodeQL does not report it.

I’d like to confirm whether this behavior is by design, and if so, what the recommended way is to model this trust boundary.

Code samples or links to source code

            function loadMessageLogs(pageSize, continuationToken) {
                let url = '?handler=LoadMessageLogs&pageSize=' + pageSize;
                if (continuationToken)
                    url += '&continuationToken=' + encodeURIComponent(continuationToken);

                fetch(url)
                    .then(response => response.json())
                    .then(data => {
                        const tbody = document.querySelector("#tblMessageLogs tbody");
                        tbody.innerHTML = "";

                        if (!data.items || data.items.length === 0) {
                            messageLogs.hidden = true;
                            noMessageLogs.hidden = false;
                        }
                        else {

                            data.items.forEach(item => {
                                const link = `<a href="/MessageLogs/Details/${item.messageId}">View message</a>`;
                                const row = `<tr>
                                        <td>${item.createdDate}</td>
                                        <td>${item.messageId}</td>
                                        <td>${item.interfaceId ?? ''}</td>
                                        <td>${item.target ?? ''}</td>
                                        <td>${item.mpanCore ?? ''}</td>
                                        <td>${item.meterId ?? ''}</td>
                                        <td>${link}</td>
                                        </tr>`;
                                tbody.insertAdjacentHTML('beforeend', row);
                            });

                            PagingModule.updatePaging(data.continuationToken)
                            messageLogs.hidden = false;
                            noMessageLogs.hidden = true;
                        }
                    });
            }

In our case, data.items[*] ultimately contains data that may originate from user input stored and returned by the backend.

  • We are running the javascript-security-extended query suite.
  • No XSS issue is reported for this code.
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 16 小時
30 天內合併 PR
143

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

github/codeql 的其他 Issue

查看 github/codeql 的全部 Issue

相似的 Issue

更多 Security Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。