Skip to content

Fix for code scanning alert no. 71: Incomplete URL substring sanitization - #13318

Merged
yingfeng merged 1 commit into
mainfrom
alert-autofix-71
Mar 2, 2026
Merged

yingfeng merged 1 commit into
mainfrom
alert-autofix-71

Conversation

@yingfeng

@yingfeng yingfeng commented Mar 2, 2026

Copy link
Copy Markdown
Member

Potential fix for https://github.com/infiniflow/ragflow/security/code-scanning/71

In general, instead of using String.prototype.includes on the entire URL string, parse the URL and make decisions based on its host (or hostname) field. This avoids cases where the trusted domain appears in the path, query, or as part of a different hostname.

Here, payload.source_fid is set to 'siliconflow_intl' if postBody.base_url “contains” api.siliconflow.com. To keep behavior for correct inputs but close the hole, we should:

  1. Safely parse postBody.base_url using the standard URL class.
  2. Extract the hostname (url.hostname).
  3. Compare it appropriately:
    • If we only want the exact host api.siliconflow.com, use strict equality.
    • If international endpoints may include subdomains like foo.api.siliconflow.com, allow those via suffix check on the hostname.
  4. Fall back to LLMFactory.SILICONFLOW if parsing fails or the host does not match.

Concretely, in web/src/pages/user-setting/setting-model/hooks.tsx, in the onApiKeySavingOk callback where payload.source_fid is set, replace the toLowerCase().includes('api.siliconflow.com') logic with a small block that:

  • Initializes a local let sourceFid = LLMFactory.SILICONFLOW;
  • If postBody.base_url is present, attempts new URL(postBody.base_url) inside a try/catch, lowercases url.hostname, and checks whether it equals api.siliconflow.com or ends with .api.siliconflow.com.
  • Assigns payload.source_fid = sourceFid.

No new external dependencies are required; URL is available in modern browsers and Node, and TypeScript understands it.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…g sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@yingfeng
yingfeng requested a review from Magicbook1108 March 2, 2026 09:33
@yingfeng
yingfeng marked this pull request as ready for review March 2, 2026 09:33
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 2, 2026
@yingfeng yingfeng added ci Continue Integration and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Mar 2, 2026
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Mar 2, 2026
@yingfeng
yingfeng marked this pull request as draft March 2, 2026 09:33
@yingfeng
yingfeng marked this pull request as ready for review March 2, 2026 09:33
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 2, 2026

@Magicbook1108 Magicbook1108 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yingfeng yingfeng changed the title Potential fix for code scanning alert no. 71: Incomplete URL substring sanitization Fix for code scanning alert no. 71: Incomplete URL substring sanitization Mar 2, 2026
@yingfeng
yingfeng merged commit a806f7b into main Mar 2, 2026
6 checks passed
@codecov

codecov Bot commented Mar 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (5fc3bd3) to head (c0a39f1).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #13318       +/-   ##
===========================================
- Coverage   47.18%        0   -47.19%     
===========================================
  Files          44        0       -44     
  Lines        9748        0     -9748     
  Branches      110        0      -110     
===========================================
- Hits         4600        0     -4600     
+ Misses       5135        0     -5135     
+ Partials       13        0       -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng deleted the alert-autofix-71 branch March 2, 2026 11:15
guptas6est pushed a commit to Nordix/ragflow that referenced this pull request Mar 5, 2026
…g sanitization (infiniflow#13318)

Potential fix for
[https://github.com/infiniflow/ragflow/security/code-scanning/71](https://github.com/infiniflow/ragflow/security/code-scanning/71)

In general, instead of using `String.prototype.includes` on the entire
URL string, parse the URL and make decisions based on its `host` (or
`hostname`) field. This avoids cases where the trusted domain appears in
the path, query, or as part of a different hostname.

Here, `payload.source_fid` is set to `'siliconflow_intl'` if
`postBody.base_url` “contains” `api.siliconflow.com`. To keep behavior
for correct inputs but close the hole, we should:

1. Safely parse `postBody.base_url` using the standard `URL` class.
2. Extract the hostname (`url.hostname`).
3. Compare it appropriately:
- If we only want the exact host `api.siliconflow.com`, use strict
equality.
- If international endpoints may include subdomains like
`foo.api.siliconflow.com`, allow those via suffix check on the hostname.
4. Fall back to `LLMFactory.SILICONFLOW` if parsing fails or the host
does not match.

Concretely, in `web/src/pages/user-setting/setting-model/hooks.tsx`, in
the `onApiKeySavingOk` callback where `payload.source_fid` is set,
replace the `toLowerCase().includes('api.siliconflow.com')` logic with a
small block that:

- Initializes a local `let sourceFid = LLMFactory.SILICONFLOW;`
- If `postBody.base_url` is present, attempts `new
URL(postBody.base_url)` inside a `try/catch`, lowercases `url.hostname`,
and checks whether it equals `api.siliconflow.com` or ends with
`.api.siliconflow.com`.
- Assigns `payload.source_fid = sourceFid`.

No new external dependencies are required; `URL` is available in modern
browsers and Node, and TypeScript understands it.


_Suggested fixes powered by Copilot Autofix. Review carefully before
merging._

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
writinwaters pushed a commit to writinwaters/ragflow that referenced this pull request Apr 10, 2026
…g sanitization (infiniflow#13318)

Potential fix for
[https://github.com/infiniflow/ragflow/security/code-scanning/71](https://github.com/infiniflow/ragflow/security/code-scanning/71)

In general, instead of using `String.prototype.includes` on the entire
URL string, parse the URL and make decisions based on its `host` (or
`hostname`) field. This avoids cases where the trusted domain appears in
the path, query, or as part of a different hostname.

Here, `payload.source_fid` is set to `'siliconflow_intl'` if
`postBody.base_url` “contains” `api.siliconflow.com`. To keep behavior
for correct inputs but close the hole, we should:

1. Safely parse `postBody.base_url` using the standard `URL` class.
2. Extract the hostname (`url.hostname`).
3. Compare it appropriately:
- If we only want the exact host `api.siliconflow.com`, use strict
equality.
- If international endpoints may include subdomains like
`foo.api.siliconflow.com`, allow those via suffix check on the hostname.
4. Fall back to `LLMFactory.SILICONFLOW` if parsing fails or the host
does not match.

Concretely, in `web/src/pages/user-setting/setting-model/hooks.tsx`, in
the `onApiKeySavingOk` callback where `payload.source_fid` is set,
replace the `toLowerCase().includes('api.siliconflow.com')` logic with a
small block that:

- Initializes a local `let sourceFid = LLMFactory.SILICONFLOW;`
- If `postBody.base_url` is present, attempts `new
URL(postBody.base_url)` inside a `try/catch`, lowercases `url.hostname`,
and checks whether it equals `api.siliconflow.com` or ends with
`.api.siliconflow.com`.
- Assigns `payload.source_fid = sourceFid`.

No new external dependencies are required; `URL` is available in modern
browsers and Node, and TypeScript understands it.


_Suggested fixes powered by Copilot Autofix. Review carefully before
merging._

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
SailedApple1991 pushed a commit to SailedApple1991/greenlaw-ragflow that referenced this pull request Apr 12, 2026
…g sanitization (infiniflow#13318)

Potential fix for
[https://github.com/infiniflow/ragflow/security/code-scanning/71](https://github.com/infiniflow/ragflow/security/code-scanning/71)

In general, instead of using `String.prototype.includes` on the entire
URL string, parse the URL and make decisions based on its `host` (or
`hostname`) field. This avoids cases where the trusted domain appears in
the path, query, or as part of a different hostname.

Here, `payload.source_fid` is set to `'siliconflow_intl'` if
`postBody.base_url` “contains” `api.siliconflow.com`. To keep behavior
for correct inputs but close the hole, we should:

1. Safely parse `postBody.base_url` using the standard `URL` class.
2. Extract the hostname (`url.hostname`).
3. Compare it appropriately:
- If we only want the exact host `api.siliconflow.com`, use strict
equality.
- If international endpoints may include subdomains like
`foo.api.siliconflow.com`, allow those via suffix check on the hostname.
4. Fall back to `LLMFactory.SILICONFLOW` if parsing fails or the host
does not match.

Concretely, in `web/src/pages/user-setting/setting-model/hooks.tsx`, in
the `onApiKeySavingOk` callback where `payload.source_fid` is set,
replace the `toLowerCase().includes('api.siliconflow.com')` logic with a
small block that:

- Initializes a local `let sourceFid = LLMFactory.SILICONFLOW;`
- If `postBody.base_url` is present, attempts `new
URL(postBody.base_url)` inside a `try/catch`, lowercases `url.hostname`,
and checks whether it equals `api.siliconflow.com` or ends with
`.api.siliconflow.com`.
- Assigns `payload.source_fid = sourceFid`.

No new external dependencies are required; `URL` is available in modern
browsers and Node, and TypeScript understands it.


_Suggested fixes powered by Copilot Autofix. Review carefully before
merging._

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
JasleenKaurSethi pushed a commit to stackhpc/ragflow that referenced this pull request Apr 28, 2026
…g sanitization (infiniflow#13318)

Potential fix for
[https://github.com/infiniflow/ragflow/security/code-scanning/71](https://github.com/infiniflow/ragflow/security/code-scanning/71)

In general, instead of using `String.prototype.includes` on the entire
URL string, parse the URL and make decisions based on its `host` (or
`hostname`) field. This avoids cases where the trusted domain appears in
the path, query, or as part of a different hostname.

Here, `payload.source_fid` is set to `'siliconflow_intl'` if
`postBody.base_url` “contains” `api.siliconflow.com`. To keep behavior
for correct inputs but close the hole, we should:

1. Safely parse `postBody.base_url` using the standard `URL` class.
2. Extract the hostname (`url.hostname`).
3. Compare it appropriately:
- If we only want the exact host `api.siliconflow.com`, use strict
equality.
- If international endpoints may include subdomains like
`foo.api.siliconflow.com`, allow those via suffix check on the hostname.
4. Fall back to `LLMFactory.SILICONFLOW` if parsing fails or the host
does not match.

Concretely, in `web/src/pages/user-setting/setting-model/hooks.tsx`, in
the `onApiKeySavingOk` callback where `payload.source_fid` is set,
replace the `toLowerCase().includes('api.siliconflow.com')` logic with a
small block that:

- Initializes a local `let sourceFid = LLMFactory.SILICONFLOW;`
- If `postBody.base_url` is present, attempts `new
URL(postBody.base_url)` inside a `try/catch`, lowercases `url.hostname`,
and checks whether it equals `api.siliconflow.com` or ends with
`.api.siliconflow.com`.
- Assigns `payload.source_fid = sourceFid`.

No new external dependencies are required; `URL` is available in modern
browsers and Node, and TypeScript understands it.


_Suggested fixes powered by Copilot Autofix. Review carefully before
merging._

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants