Skip to content

feat: add secure-input support via _DEEPIN_SECURE_INPUT property - #379

Open
justforlxz wants to merge 1 commit into
masterfrom
mika/secure-input
Open

feat: add secure-input support via _DEEPIN_SECURE_INPUT property#379
justforlxz wants to merge 1 commit into
masterfrom
mika/secure-input

Conversation

@justforlxz

@justforlxz justforlxz commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

Add support for the _DEEPIN_SECURE_INPUT X11 window property to mark windows as secure-input windows. When a window has this property set and the restrict daemon activates secure-input mode via the UACE extension, synthetic/injected input (XTEST, SendEvent of input-class events, XWarpPointer) is rejected by the X server.

Changes

  • src/atoms.cpp/h: Add _DEEPIN_SECURE_INPUT atom alongside _DEEPIN_PROHIBIT_SCREENSHOT
  • src/events.cpp: PropertyNotify handler for _DEEPIN_SECURE_INPUT property (mirror updateProhibitScreenshot)
  • src/x11window.h/cpp: Add isSecureInputWindow()/updateSecureInput(bool)/m_isSecureInputWindow/m_secureInputWindowId; destructor auto-clears secureInputWindowIdLists
  • src/window.h/cpp: Add isSecureInputWindow() virtual method
  • src/wayland/dderestrict_interface.h/cpp: Add secureInputWindowIdLists/setSecureInputWindow/removeSecureInputWindow

Design

  • Mirrors the existing screenshot-protection pattern (_DEEPIN_PROHIBIT_SCREENSHOT/isProhibitScreenshotWindow/protectedWindowIdLists)
  • Pure incremental addition, no changes to existing screenshot protection
  • Captures window XID at property set time for destructor cleanup (since window() is reset to XCB_WINDOW_NONE before destructor runs)

Related

Summary by Sourcery

Add secure-input window support so the compositor and restrict service can identify and manage windows that require protection from synthetic input.

New Features:

  • Support marking X11 windows as secure-input windows through the _DEEPIN_SECURE_INPUT property.
  • Track secure-input windows through the DDE restrict interface for input protection enforcement.

Bug Fixes:

  • Ensure secure-input window registrations are removed when windows are destroyed.

Add secure-input support for polkit authentication windows. When a window
has the _DEEPIN_SECURE_INPUT property set, KWin tracks it in the
DDERestrictInterface secureInputWindowIdLists and auto-clears the entry
on X11Window destruction.

Add _DEEPIN_SECURE_INPUT atom alongside existing _DEEPIN_PROHIBIT_SCREENSHOT.
Add PropertyNotify handler to observe the property. Mirror the existing
screenshot-protection pattern (isSecureInputWindow/updateSecureInput/
secureInputWindowIdLists). Store the XID in updateSecureInput setter for
destructor cleanup (window() is reset to XCB_WINDOW_NONE before dtor).

新增 _DEEPIN_SECURE_INPUT 属性支持,用于标记安全输入窗口。
KWin 通过 DDERestrictInterface 追踪安全输入窗口列表,并在窗口
销毁时自动清理。PropertyNotify 观察属性变化,与截图保护同构。

Log: 新增安全输入窗口属性支持
Influence: 拥有 _DEEPIN_SECURE_INPUT 属性的窗口被标记为安全输入窗口;
X11Window 析构时自动清理列表条目;不影响现有截图保护功能
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: justforlxz

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

Sorry @justforlxz, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds support for the _DEEPIN_SECURE_INPUT X11 property and wires it through X11 window tracking and the Wayland dde_restrict interface, mirroring the existing screenshot protection flow so secure-input windows can be tracked and cleaned up correctly.

Sequence diagram for secure-input window tracking and cleanup

sequenceDiagram
    actor Client
    participant X11Window
    participant Window
    participant WaylandServer
    participant DDERestrictInterface

    Client->>X11Window: propertyNotifyEvent(_DEEPIN_SECURE_INPUT)
    X11Window->>X11Window: updateSecureInput(isSecure)

    opt [Wayland session]
        X11Window->>Window: isSecureInputWindow()
        Window->>WaylandServer: waylandServer()
        WaylandServer->>DDERestrictInterface: ddeRestrict()
        DDERestrictInterface->>DDERestrictInterface: secureInputWindowIdLists()
        DDERestrictInterface-->>Window: contains(window())
        Window-->>X11Window: return true/false
    end

    X11Window->>X11Window: ~X11Window()
    alt [m_isSecureInputWindow && m_secureInputWindowId != XCB_WINDOW_NONE]
        X11Window->>WaylandServer: waylandServer()
        WaylandServer->>DDERestrictInterface: ddeRestrict()
        DDERestrictInterface->>DDERestrictInterface: removeSecureInputWindow(m_secureInputWindowId)
    end
Loading

File-Level Changes

Change Details Files
Introduce _DEEPIN_SECURE_INPUT atom and event handling to mark X11 windows as secure-input windows.
  • Add deepin_secure_input atom in atom registry alongside existing Deepin atoms.
  • Handle PropertyNotify events for deepin_secure_input and update per-window secure-input state.
src/atoms.cpp
src/atoms.h
src/events.cpp
Extend Window/X11Window APIs to track secure-input state and ensure Wayland restrict lists are updated and cleaned up.
  • Add virtual isSecureInputWindow() to Window and implement it by querying dde_restrict secureInputWindowIdLists.
  • Add isSecureInputWindow() override and updateSecureInput(bool) helper to X11Window, capturing the window XID when the property is set.
  • Store secure-input flags/XID in X11Window and clear stale secure-input entries from dde_restrict in the X11Window destructor.
src/window.h
src/window.cpp
src/x11window.h
src/x11window.cpp
Augment dde_restrict Wayland interface to maintain secure-input window ID lists mirroring protected-window handling.
  • Add m_secureInputWindowIdLists container to DDERestrictInterfacePrivate.
  • Implement setSecureInputWindow/removeSecureInputWindow on the private class with duplicate checks and indexed removal.
  • Expose secureInputWindowIdLists() and removeSecureInputWindow(int32_t) on DDERestrictInterface.
src/wayland/dderestrict_interface.cpp
src/wayland/dderestrict_interface.h

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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

★ 总体评分:90分

■ 【总体评价】

代码实现了安全输入窗口的标记与生命周期管理,逻辑基本正确且具备双重保险机制
代码整体质量良好,无安全漏洞,仅在列表操作等细节上存在轻微优化空间

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

代码在 X11Window::propertyNotifyEvent 中正确处理了属性变更事件,利用 !e->state 区分属性新增与删除。X11Window 的析构函数中通过检查 m_isSecureInputWindowm_secureInputWindowId 实现了清理逻辑的“双重保险”,避免了因 restrict daemon 错过 DestroyNotify 导致的列表残留问题。updateSecureInput 内联函数在更新状态的同时捕获了 XID,解决了析构时 window() 可能已失效的问题。
潜在问题:在 X11Window::isSecureInputWindow 中,当 waylandServer() 存在时调用基类查询 Wayland 列表,否则返回本地标志。若在 Xwayland 环境下,X11 窗口是否会被正确添加到 Wayland 的 m_secureInputWindowIdLists 中需要结合上下文确认,但仅从 diff 看逻辑自洽。
建议:确保在 Xwayland 场景下,X11 窗口的 ID 与 Wayland 列表中的 ID 类型匹配;考虑在 updateSecureInput 中增加对重复设置的过滤。

  • 2.代码质量(良好)✓

代码结构清晰,命名规范符合项目风格,注释详细解释了析构函数中“双重保险”的设计意图和捕获 XID 的原因。但在 DDERestrictInterfacePrivate::removeSecureInputWindow 中使用了手写的 for 循环进行遍历和删除,这在 Qt 环境下略显冗余。
潜在问题:手写循环删除列表元素容易在后续维护中引入越界或逻辑错误,且不符合 Qt 惯用法。
建议:使用 QList::removeOne 方法替代手写循环,提高代码简洁性和可读性。

  • 3.代码性能(无性能问题)✓

各项操作均为轻量级的列表查询与修改。isSecureInputWindow 中的 contains 操作为 O(n) 复杂度,但在窗口管理器中安全输入窗口的数量通常极少,不会造成性能瓶颈。析构函数中的清理操作也仅在必要时触发。
建议:无需特殊优化,保持现状即可。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码主要涉及 X11 属性监听与 Wayland 接口交互,未引入外部输入解析、命令执行或敏感信息硬编码。窗口 ID 作为整数类型传递,不存在注入风险。析构函数中的空指针检查(waylandServer()dde_restrict)有效防止了空指针解引用。

  • 建议:继续保持对指针的有效性检查,确保在异常销毁路径下的安全性。

■ 【改进建议代码示例】

diff --git a/src/wayland/dderestrict_interface.cpp b/src/wayland/dderestrict_interface.cpp
index 37267e1e58..97ed1497c7 100644
--- a/src/wayland/dderestrict_interface.cpp
+++ b/src/wayland/dderestrict_interface.cpp
@@ -159,6 +162,15 @@ void DDERestrictInterfacePrivate::removeProtectedWindow(int32_t window)
     }
 }
 
 void DDERestrictInterfacePrivate::setSecureInputWindow(int32_t window)
 {
     if (m_secureInputWindowIdLists.contains(window)) {
         return;
     }
     m_secureInputWindowIdLists.append(window);
 }
 
 void DDERestrictInterfacePrivate::removeSecureInputWindow(int32_t window)
 {
-    for (int i = 0; i < m_secureInputWindowIdLists.length(); i++) {
-        if (m_secureInputWindowIdLists[i] == window) {
-            m_secureInputWindowIdLists.removeAt(i);
-            break;
-        }
-    }
+    m_secureInputWindowIdLists.removeOne(window);
 }

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.

2 participants