github / github/codeql

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

Đang mở
#21,257 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**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 = `View message`;
const row = `
${item.createdDate}
${item.messageId}
${item.interfaceId ?? ''}
${item.target ?? ''}
${item.mpanCore ?? ''}
${item.meterId ?? ''}
${link}
`;
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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with the JavaScript security-extended query suite and review how fetch().json() responses and insertAdjacentHTML are modeled. Determine whether this flow is intentionally excluded or needs source and sink modeling, then validate the conclusion against the supplied example and confirm whether an XSS result is expected.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
security
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.