False positive: js/incomplete-hostname-regexp treats LinkifyIt.match(text) as a regex call
- 主要語言
- CodeQL
- 星號
- 10.1k
- 分支
- 2.1k
- 平均合併
- 2 天 15 小時
- 30 天內合併 PR
- 141
描述
**Description of the false positive**
`js/incomplete-hostname-regexp` treats the argument to `LinkifyIt.match(text)` as a regular expression. The receiver is a `LinkifyIt` instance from `linkify-it@6.1.0`; its argument is document text to scan for links, not a regex pattern. Literal dots in these URLs are therefore correct.
Observed with CodeQL **2.26.4**, JavaScript/TypeScript analysis, `build-mode: none`, and `github/codeql-action@cdf488f595d80d6e07e03d4674febd5ab45fa938` (v4.37.9), using the default query suite without custom queries or exclusions.
Diagnostic on the text literal:
> This string, which is used as a regular expression here, has an unescaped '.' before 'youtube.com/watc', so it might match more hosts than expected.
The linked use is `scanner.match(text)`.
**Code samples or links to source code**
Small excerpt retaining the constructor, configuration, literal and call from the reported test:
```js
import { LinkifyIt } from "linkify-it";
const scanner = new LinkifyIt({ fuzzyLink: false, fuzzyEmail: false })
.add("ftp:", null)
.add("mailto:", null)
.add("//", null);
const text =
"😀 *literal* (https://www.youtube.com/watch?v=tax4e4hBBZc), then https://store.steampowered.com/app/457140/.";
const matches = scanner.match(text);
console.log(matches.map((m) => m.raw));
```
With `linkify-it@6.1.0`, the API returns matches for the two literal URLs. The package's `build/index.d.ts` declares `match(text: string): Match[] | null`; `build/index.mjs` implements the method by scanning that document text with the library's link recognizers.
[Exact reported source at the PR merge revision](https://github.com/MaksymShostak/steam-community-bbcode/blob/34d9cea0dccc2fbf8fae35558333b23b5e049758/test/link-recognition-qualification.test.js#L4-L13).
[Source at the immutable PR head](https://github.com/MaksymShostak/steam-community-bbcode/blob/c1c5de6ec6685b5f2c36aac24470dfb41634f961/test/link-recognition-qualification.test.js#L4-L13).
Validation: `node --test test/link-recognition-qualification.test.js` passes 1/1, including exact URL and offset assertions. The hosted CodeQL analysis reports the finding in the linked full test. The reduced excerpt above has not been separately analyzed with CodeQL; no claim is made that it is the smallest scanner reproducer.
Expected: recognize that this imported library's `match` method consumes document text, so these literals should not be classified as hostname regular expressions. Ordinary `String.match` regex findings should remain enabled.
Related precedent: https://github.com/github/codeql/pull/19854 explicitly models Sinon's `match` calls as non-RegExp. I found no existing `linkify-it` report in the upstream search.
**URL to the alert on GitHub code scanning (optional)**
https://github.com/MaksymShostak/steam-community-bbcode/security/code-scanning/2
[Failing PR check](https://github.com/MaksymShostak/steam-community-bbcode/pull/4/checks?check_run_id=103162822542).
貢獻指南
研究方向
檢查 js/incomplete-hostname-regexp 查詢及其程式庫模型,然後比較 PR 19854 中的 Sinon 先例。針對 test/link-recognition-qualification.test.js 重新執行連結的 CodeQL 警示;當不再回報 LinkifyIt.match(text) 字面值,同時一般的 String.match 正規表示式發現仍保持啟用時,即完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript
- 領域
- security
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 活躍
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100