Skip to content

fix: improve OS version detefix: improve OS version detection for Windows 11 (#6949)ction for Windows 11 (#6949)#8357

Open
DocJlm wants to merge 1 commit intohalo-dev:mainfrom
DocJlm:fix/improve-os-version-detection
Open

fix: improve OS version detefix: improve OS version detection for Windows 11 (#6949)ction for Windows 11 (#6949)#8357
DocJlm wants to merge 1 commit intohalo-dev:mainfrom
DocJlm:fix/improve-os-version-detection

Conversation

@DocJlm
Copy link
Copy Markdown

@DocJlm DocJlm commented Feb 21, 2026

What type of PR is this?

/kind bug
/kind improvement

What this PR does / why we need it:

Windows 11 is incorrectly detected as Windows 10 in device fingerprint info,
because both Windows 10 and 11 report as "Windows NT 10.0" in User-Agent string.

This PR:

  1. Adds a Windows NT version-to-friendly-name mapping (e.g., "NT 10.0" → "Windows 10",
    "NT 6.1" → "Windows 7") so the OS info is more user-friendly
  2. Adds support for Sec-CH-UA-Platform-Version Client Hints header to distinguish
    Windows 11 (platform version >= 13) from Windows 10
  3. Adds unit tests for Windows 10/11 detection with and without Client Hints,
    and tests for older Windows versions (7, 8.1)

Which issue(s) this PR fixes:

Fixes #6949

Special notes for your reviewer:

  • The parse(String userAgent) method is preserved for backward compatibility.
    A new overload parse(String userAgent, HttpHeaders headers) is added.
  • Windows 11 detection relies on the Sec-CH-UA-Platform-Version header.
    If the header is not present, it falls back to "Windows 10" (safe default).
  • The threshold of major version >= 13 for Windows 11 is based on
    Microsoft's official documentation.

Does this PR introduce a user-facing change?

修复设备登录信息中 Windows 11 被错误识别为 Windows 10 的问题,
现在支持通过 Client Hints 精准区分 Windows 10/11,
并以用户友好的格式显示 OS 名称(如 "Windows 10" 而非 "Windows NT 10.0")。

Windows 11 reports as "Windows NT 10.0" in User-Agent string, same as
Windows 10, causing incorrect OS detection. This commit:

- Add Windows NT version-to-friendly-name mapping (e.g., NT 10.0 → Windows 10)
- Support Sec-CH-UA-Platform-Version Client Hints header to distinguish
  Windows 11 (platform version >= 13) from Windows 10
- Display user-friendly OS names (e.g., "Windows 10" instead of "Windows NT 10.0")
- Add unit tests for Windows 10/11 detection with and without Client Hints
@f2c-ci-robot f2c-ci-robot Bot added kind/bug Categorizes issue or PR as related to a bug. kind/improvement Categorizes issue or PR as related to a improvement. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 21, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 21, 2026

CLA assistant check
All committers have signed the CLA.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Feb 21, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign guqing for approval. For more information see the Code Review Process.

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

@sonarqubecloud
Copy link
Copy Markdown

@f2c-ci-robot f2c-ci-robot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves device fingerprint OS detection for Windows by mapping Windows NT versions to user-friendly Windows names and using the Sec-CH-UA-Platform-Version Client Hints header to distinguish Windows 11 from Windows 10.

Changes:

  • Add Windows NT version → friendly Windows version mapping and Windows 11 detection via Sec-CH-UA-Platform-Version.
  • Add a new DeviceInfo.parse(String userAgent, HttpHeaders headers) overload while keeping the original parse(String userAgent) for compatibility.
  • Expand unit tests to cover Windows 10/11 detection with/without Client Hints and older Windows versions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
application/src/main/java/run/halo/app/security/device/DeviceServiceImpl.java Enhance OS parsing to output friendly Windows names and leverage Client Hints to detect Windows 11.
application/src/test/java/run/halo/app/security/device/DeviceServiceImplTest.java Add unit tests for Windows 10/11 and older Windows version parsing scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +250 to 256
public static DeviceInfo parse(String userAgent,
org.springframework.http.HttpHeaders headers) {
return new DeviceInfo(concat(parseBrowser(userAgent).name(),
parseBrowser(userAgent).version()),
concat(parseOperatingSystem(userAgent).name(),
parseOperatingSystem(userAgent).version())
concat(parseOperatingSystem(userAgent, headers).name(),
parseOperatingSystem(userAgent, headers).version())
);
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

DeviceInfo.parse(userAgent, headers) calls parseBrowser(userAgent) and parseOperatingSystem(userAgent, headers) twice each, which repeats regex matching and does unnecessary work. Store the parsed browser/OS Pair in local variables and reuse them when building the DeviceInfo result.

Copilot uses AI. Check for mistakes.
Comment on lines +250 to +251
public static DeviceInfo parse(String userAgent,
org.springframework.http.HttpHeaders headers) {
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

HttpHeaders is imported at the top of this file, but the new overload uses the fully-qualified org.springframework.http.HttpHeaders in its signature. For consistency/readability, prefer using the imported HttpHeaders type here (or drop the import if fully-qualifying is intentional).

Suggested change
public static DeviceInfo parse(String userAgent,
org.springframework.http.HttpHeaders headers) {
public static DeviceInfo parse(String userAgent, HttpHeaders headers) {

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.84%. Comparing base (42c374d) to head (dc413b4).
⚠️ Report is 534 commits behind head on main.

Files with missing lines Patch % Lines
...un/halo/app/security/device/DeviceServiceImpl.java 71.42% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8357      +/-   ##
============================================
+ Coverage     59.55%   60.84%   +1.29%     
- Complexity     3812     3999     +187     
============================================
  Files           677      698      +21     
  Lines         23248    23872     +624     
  Branches       1500     1559      +59     
============================================
+ Hits          13846    14526     +680     
+ Misses         8764     8614     -150     
- Partials        638      732      +94     

☔ 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.

@f2c-ci-robot f2c-ci-robot Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2026
@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 17, 2026

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@JohnNiang
Copy link
Copy Markdown
Member

Hi @DocJlm , thank you for your contribution!

这里我建议使用专门的 UA 解析库来解决这个问题。

如果你有时间的话,可以试试;如果没有时间的话,我可以单独提交 PR 修复此问题。

Copy link
Copy Markdown
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

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

Hi @DocJlm , thank you for your contribution again!

目前,通过 UA 几乎是不可能解析 Windows 11 的。另外请求头 Sec-CH-UA 尚处于实验性阶段,不建议通过这个请求头进行解析。

综上,我们将暂时关闭当前 PR,直到有一个更好的解决方案。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. kind/improvement Categorizes issue or PR as related to a improvement. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

浏览器指纹

4 participants