Skip to content

feat: 解析DHCP Captive-Portal选项识别portal网络 - #664

Open
caixr23 wants to merge 1 commit into
masterfrom
agent/agent/38039130f1aa
Open

caixr23 wants to merge 1 commit into
masterfrom
agent/agent/38039130f1aa

Conversation

@caixr23

@caixr23 caixr23 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Cherry-pick from Gerrit change 421605

将 Gerrit change https://gerrit.uniontech.com/c/dde-network-core/+/421605 摘取到 linuxdeepin/dde-network-core 仓库,保留原始提交说明。

变更内容

从主连接设备的DHCP4配置中解析NM导出的Captive-Portal URL: 优先取 default_url (RFC 8910, option 114), 兜底取 v4_captive_portal (RFC 7710 遗留, option 160), 补齐 HTTP 探测的两个盲区: 探测判 Portal 但无跳转 URL 时兜底、探测失败但设备未断开时升级为 Portal; 对 URL 做 scheme 白名单与控制字符校验, 拒绝不可信 DHCP 服务端下发的非法值。

冲突解决

cherry-pick 时 network-service-plugin/src/system/connectivitychecker.cpp 有一处冲突:目标仓库 master 已移除 if 块前的 setPortalUrl(QString()),Gerrit change 将其移入 if (disconnectCount == devices.size()) 块内并添加注释。解决方式:保留 Gerrit change 的版本。

原始信息

Summary by Sourcery

识别并标记由 DHCP Captive-Portal 选项声明的需认证网络,同时增强 HTTP 探测异常场景下的网络状态判断。

New Features:

  • Detect captive-portal networks using DHCP-provided Captive-Portal URLs from the primary connection, supporting RFC 8910 and legacy RFC 7710 options.

Bug Fixes:

  • Improve captive-portal detection when HTTP probing is falsely negative or fails while network devices remain connected.
  • Reject unsafe DHCP-provided portal URLs that use unsupported schemes or contain whitespace and control characters.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

解析并校验主连接设备的 DHCP Captive-Portal URL,并将其用于补足 HTTP 探测结果中的门户网络判定盲区。

  • network-service-plugin/src/system/connectivitychecker.cpp L306-314, L338-351, L429-482 (+1 small edits)
  • network-service-plugin/src/system/connectivitychecker.h L97-98

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="network-service-plugin/src/system/connectivitychecker.cpp" line_range="470" />
<code_context>
+
+        const QVariantMap options = dhcp4->options();
+        for (const char *key : { "default_url", "v4_captive_portal" }) {
+            const QString url = options.value(QLatin1String(key)).toString().trimmed();
+            if (url.isEmpty() || !isSafePortalUrl(url)) {
+                if (!url.isEmpty())
</code_context>
<issue_to_address>
**Authenticated clients appear captive**

When the network continues advertising a Captive-Portal URI after authentication, or an HTTP probe fails for a non-captive reason, `realStartCheck()` treats a nonempty result from `dhcpCaptivePortalUrl()` as proof that authentication is required, so it sets connectivity to `Portal` and callers report a captive network.

Determine captive status from the API response or connectivity check rather than treating the URI’s presence as proof of captive status.

Also at `network-service-plugin/src/system/connectivitychecker.cpp:308-313`, `network-service-plugin/src/system/connectivitychecker.cpp:344-348`, `network-service-plugin/src/system/connectivitychecker.cpp:476-478`.
</issue_to_address>

### Comment 2
<location path="network-service-plugin/src/system/connectivitychecker.cpp" line_range="470" />
<code_context>
+
+        const QVariantMap options = dhcp4->options();
+        for (const char *key : { "default_url", "v4_captive_portal" }) {
+            const QString url = options.value(QLatin1String(key)).toString().trimmed();
+            if (url.isEmpty() || !isSafePortalUrl(url)) {
+                if (!url.isEmpty())
</code_context>
<issue_to_address>
**Users see API data, not login page**

When the DHCP option is an RFC 8910 API URI whose response identifies a separate user portal URL, `dhcpCaptivePortalUrl()` returns the API URI unchanged, and `SessionContainer::openPortalUrl` passes it to `UrlHelper::openUrl`, so the browser displays API data instead of the authentication page.

Resolve the API response’s user-facing portal URL and pass that URL to the browser.

Also at `network-service-plugin/src/system/connectivitychecker.cpp:308-313`, `network-service-plugin/src/system/connectivitychecker.cpp:346-348`, `network-service-plugin/src/system/connectivitychecker.cpp:478`.
</issue_to_address>

### Comment 3
<location path="network-service-plugin/src/system/connectivitychecker.cpp" line_range="308" />
<code_context>
-            setConnectivity(network::service::Connectivity::Full);
+            // HTTP探测未见劫持时,若DHCP下发了Captive-Portal选项(RFC 8910),
+            // 说明该网络仍需认证(如探测域名被网关白名单放行导致假阴性)
+            portalUrl = dhcpCaptivePortalUrl();
+            if (portalUrl.isEmpty()) {
+                // if the portal is empty, I think it ok
</code_context>
<issue_to_address>
**DHCP fallback is skipped in NM mode**

When `enableConnectivity` is false, `ConnectivityProcesser::createConnectivityChecker(false)` selects `NMConnectionvityChecker`, which never calls `dhcpCaptivePortalUrl()` and exposes no DHCP-derived portal URL. Networks using that supported mode therefore miss the new DHCP-based detection and portal link.

Apply the DHCP captive-portal lookup and URL propagation in the NM checker path as well, or otherwise ensure this mode receives the same fallback.
</issue_to_address>

### Comment 4
<location path="network-service-plugin/src/system/connectivitychecker.cpp" line_range="434-443" />
<code_context>
+static bool isSafePortalUrl(const QString &rawUrl)
+{
+    const QString url = rawUrl.trimmed();
+    if (url.size() < 8 || url.size() > 2048)
+        return false;
+
+    for (const QChar &ch : url) {
+        const uint code = ch.unicode();
+        if (code <= 0x20 || code == 0x7f)
+            return false;
+    }
+
+    return url.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)
+           || url.startsWith(QLatin1String("https://"), Qt::CaseInsensitive);
+}
</code_context>
<issue_to_address>
**Malformed portal URL is accepted**

When a DHCP server supplies a scheme-only or otherwise malformed HTTP(S) URL, `isSafePortalUrl()` checks only the scheme prefix, so `dhcpCaptivePortalUrl()` accepts the malformed value and returns it instead of trying a valid legacy-option URL; callers expose an unusable portal URL.

Parse and validate the URL’s structure before accepting it, so malformed values are rejected and the legacy option can be tried.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨


const QVariantMap options = dhcp4->options();
for (const char *key : { "default_url", "v4_captive_portal" }) {
const QString url = options.value(QLatin1String(key)).toString().trimmed();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Authenticated clients appear captive

When the network continues advertising a Captive-Portal URI after authentication, or an HTTP probe fails for a non-captive reason, realStartCheck() treats a nonempty result from dhcpCaptivePortalUrl() as proof that authentication is required, so it sets connectivity to Portal and callers report a captive network.

Determine captive status from the API response or connectivity check rather than treating the URI’s presence as proof of captive status.

Also at network-service-plugin/src/system/connectivitychecker.cpp:308-313, network-service-plugin/src/system/connectivitychecker.cpp:344-348, network-service-plugin/src/system/connectivitychecker.cpp:476-478.

Prompt for AI agents
In `network-service-plugin/src/system/connectivitychecker.cpp` at line 470:

**Authenticated clients appear captive**

When the network continues advertising a Captive-Portal URI after authentication, or an HTTP probe fails for a non-captive reason, `realStartCheck()` treats a nonempty result from `dhcpCaptivePortalUrl()` as proof that authentication is required, so it sets connectivity to `Portal` and callers report a captive network.

Determine captive status from the API response or connectivity check rather than treating the URI’s presence as proof of captive status.

Also at `network-service-plugin/src/system/connectivitychecker.cpp:308-313`, `network-service-plugin/src/system/connectivitychecker.cpp:344-348`, `network-service-plugin/src/system/connectivitychecker.cpp:476-478`.


const QVariantMap options = dhcp4->options();
for (const char *key : { "default_url", "v4_captive_portal" }) {
const QString url = options.value(QLatin1String(key)).toString().trimmed();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Users see API data, not login page

When the DHCP option is an RFC 8910 API URI whose response identifies a separate user portal URL, dhcpCaptivePortalUrl() returns the API URI unchanged, and SessionContainer::openPortalUrl passes it to UrlHelper::openUrl, so the browser displays API data instead of the authentication page.

Resolve the API response’s user-facing portal URL and pass that URL to the browser.

Also at network-service-plugin/src/system/connectivitychecker.cpp:308-313, network-service-plugin/src/system/connectivitychecker.cpp:346-348, network-service-plugin/src/system/connectivitychecker.cpp:478.

Prompt for AI agents
In `network-service-plugin/src/system/connectivitychecker.cpp` at line 470:

**Users see API data, not login page**

When the DHCP option is an RFC 8910 API URI whose response identifies a separate user portal URL, `dhcpCaptivePortalUrl()` returns the API URI unchanged, and `SessionContainer::openPortalUrl` passes it to `UrlHelper::openUrl`, so the browser displays API data instead of the authentication page.

Resolve the API response’s user-facing portal URL and pass that URL to the browser.

Also at `network-service-plugin/src/system/connectivitychecker.cpp:308-313`, `network-service-plugin/src/system/connectivitychecker.cpp:346-348`, `network-service-plugin/src/system/connectivitychecker.cpp:478`.

setConnectivity(network::service::Connectivity::Full);
// HTTP探测未见劫持时,若DHCP下发了Captive-Portal选项(RFC 8910),
// 说明该网络仍需认证(如探测域名被网关白名单放行导致假阴性)
portalUrl = dhcpCaptivePortalUrl();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · DHCP fallback is skipped in NM mode

When enableConnectivity is false, ConnectivityProcesser::createConnectivityChecker(false) selects NMConnectionvityChecker, which never calls dhcpCaptivePortalUrl() and exposes no DHCP-derived portal URL. Networks using that supported mode therefore miss the new DHCP-based detection and portal link.

Apply the DHCP captive-portal lookup and URL propagation in the NM checker path as well, or otherwise ensure this mode receives the same fallback.

Prompt for AI agents
In `network-service-plugin/src/system/connectivitychecker.cpp` at line 308:

**DHCP fallback is skipped in NM mode**

When `enableConnectivity` is false, `ConnectivityProcesser::createConnectivityChecker(false)` selects `NMConnectionvityChecker`, which never calls `dhcpCaptivePortalUrl()` and exposes no DHCP-derived portal URL. Networks using that supported mode therefore miss the new DHCP-based detection and portal link.

Apply the DHCP captive-portal lookup and URL propagation in the NM checker path as well, or otherwise ensure this mode receives the same fallback.

Comment on lines +434 to +443
if (url.size() < 8 || url.size() > 2048)
return false;

for (const QChar &ch : url) {
const uint code = ch.unicode();
if (code <= 0x20 || code == 0x7f)
return false;
}

return url.startsWith(QLatin1String("http://"), Qt::CaseInsensitive)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Malformed portal URL is accepted

When a DHCP server supplies a scheme-only or otherwise malformed HTTP(S) URL, isSafePortalUrl() checks only the scheme prefix, so dhcpCaptivePortalUrl() accepts the malformed value and returns it instead of trying a valid legacy-option URL; callers expose an unusable portal URL.

Parse and validate the URL’s structure before accepting it, so malformed values are rejected and the legacy option can be tried.

Prompt for AI agents
In `network-service-plugin/src/system/connectivitychecker.cpp` at lines 434-443:

**Malformed portal URL is accepted**

When a DHCP server supplies a scheme-only or otherwise malformed HTTP(S) URL, `isSafePortalUrl()` checks only the scheme prefix, so `dhcpCaptivePortalUrl()` accepts the malformed value and returns it instead of trying a valid legacy-option URL; callers expose an unusable portal URL.

Parse and validate the URL’s structure before accepting it, so malformed values are rejected and the legacy option can be tried.

1. Parse the Captive-Portal URL from the primary connection device's DHCP4
   configuration via NM, preferring default_url (RFC 8910, option 114) and
   falling back to v4_captive_portal (RFC 7710 legacy, option 160).
2. Fill two HTTP probing blind spots: fall back when the probe detects Portal
   but has no redirect URL, and escalate to Portal when the probe fails but
   the device is not disconnected.
3. Validate the URL with a scheme allowlist and control-character
   sanitization, rejecting illegal values from untrusted DHCP servers.

Log: connect to captive portal authentication networks
Influence:
1. Networks where the DHCP server provides Captive-Portal options

feat: 解析DHCP Captive-Portal选项识别portal网络

1. 从主连接设备的DHCP4配置中解析NM导出的Captive-Portal URL,优先取
   default_url(RFC 8910, option 114),兜底取v4_captive_portal(RFC 7710
   遗留, option 160)。
2. 补齐HTTP探测的两个盲区:探测判Portal但无跳转URL时兜底、探测失败但
   设备未断开时升级为Portal。
3. 对URL做scheme白名单与控制字符校验,拒绝不可信DHCP服务端下发的非法值。

Log: 连接captive portal认证网络
Influence:
1. DHCP下发了Captive-Portal选项的网络

PMS: BUG-381939
Change-Id: I80e045154e039f7606e7ffbcda8904dd1164ff59
@caixr23
caixr23 force-pushed the agent/agent/38039130f1aa branch from 4e5888d to 1fe2774 Compare November 19, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants