Skip to content

fix: disable the popup menu when show password mode#505

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
ut003640:master
Feb 27, 2026
Merged

fix: disable the popup menu when show password mode#505
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
ut003640:master

Conversation

@ut003640
Copy link
Contributor

disable the popup menu when show password mode

PMS: BUG-351233

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

Please try again later or upgrade to continue using Sourcery

disable the popup menu when show password mode

PMS: BUG-351233
@deepin-ci-robot
Copy link

deepin pr auto review

针对这段 git diff 的代码审查,我将从语法逻辑、代码质量、代码性能和代码安全四个方面进行分析。

1. 语法逻辑

  • 审查结果:通过。
  • 分析:代码逻辑是正确的。通过添加一个 MouseArea 并设置 acceptedButtons: Qt.RightButton,确实可以拦截右键点击事件。当 enabled 属性为 true(即父组件处于密码模式 TextInput.Password)时,该 MouseArea 会捕获右键事件,从而阻止其传播到父组件(即 TextInput),进而禁用了右键菜单。当 enabledfalse 时,事件穿透,右键菜单正常显示。

2. 代码质量

  • 审查结果:良好,但有改进空间。
  • 分析
    • 优点:代码简洁,利用 QML 的属性绑定机制实现了动态控制,符合 QML 的声明式编程风格。
    • 改进建议:代码中使用了 parent 关键字来引用父对象(即 TextInput)。虽然在当前上下文中是可行的,但在复杂的 QML 对象树中,直接依赖 parent 可能会降低代码的可维护性和可读性。如果将来在 TextInput 和这个 MouseArea 之间插入了一个中间层(例如一个 Item 用于布局),parent 的指向就会改变,导致逻辑失效。
    • 建议:给 TextInput 添加一个 id(例如 id: passwordInput),然后在 MouseArea 中通过 passwordInput.echoMode 进行引用。这样更加健壮。

3. 代码性能

  • 审查结果:优秀。
  • 分析
    • 这是一个非常轻量级的修改。添加一个 MouseArea 不会带来显著的内存开销或 CPU 占用。
    • 属性绑定 enabled: parent.echoMode === TextInput.Password 是高效的,只有在 echoMode 改变时才会触发重新计算。

4. 代码安全

  • 审查结果:有效,但存在局限性。
  • 分析
    • 正面影响:该修改确实阻止了用户通过右键菜单在密码显示为明文时进行“复制”操作,防止了密码直接通过剪贴板泄露。
    • 局限性/潜在风险
      1. 系统级快捷键:虽然禁用了右键菜单,但通常操作系统(如 Linux/Deepin)仍然允许通过键盘快捷键(如 Ctrl+CCtrl+Insert)进行复制。如果用户在明文模式下按下这些快捷键,密码依然会被复制到剪贴板。
      2. 屏幕录制/截图:如果密码以明文显示,任何能够截取屏幕内容的软件(截图、录屏、甚至远端屏幕共享)都能直接获取密码。
      3. 物理窥视:明文显示最大的风险在于“肩窥”(Shoulder Surfing),即旁边的人直接看到屏幕上的密码。

综合改进建议

为了提高代码的健壮性并增强安全性,建议进行如下修改:

  1. 代码健壮性:使用 id 引用代替 parent
  2. 安全性增强:在明文模式下,除了禁用右键,还应考虑禁用键盘快捷键复制功能(通过 Keys.onPressed 拦截)。

优化后的代码示例:

TextField {
    id: passwordInput // 添加 ID
    // ... 其他属性保持不变 ...

    // 在显示明文时禁用右键菜单和复制快捷键
    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.RightButton
        // 使用 id 引用,更加安全
        enabled: passwordInput.echoMode === TextInput.Password
    }

    // 增强安全性:在明文模式下拦截复制快捷键
    Keys.onPressed: function(event) {
        if (passwordInput.echoMode === TextInput.Normal) {
            // 检测是否是复制相关的组合键 (Ctrl+C, Ctrl+Insert)
            if ((event.key === Qt.Key_C || event.key === Qt.Key_Insert) && (event.modifiers & Qt.ControlModifier)) {
                event.accepted = true; // 接受事件,阻止默认的复制行为
            }
        }
    }
}

总结
原代码修改在逻辑上是正确的,能够解决部分通过右键菜单复制密码的安全隐患。但为了达到更好的安全性和代码可维护性,建议采用上述优化方案,特别是要考虑到快捷键复制的情况。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, ut003640

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

@ut003640
Copy link
Contributor Author

/merge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Feb 27, 2026

This pr cannot be merged! (status: unstable)

@ut003640
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Feb 27, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 3a921bd into linuxdeepin:master Feb 27, 2026
16 of 18 checks passed
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