refactor(security): remove unused code and simplify service enable logic#497
Conversation
pppanghu77
commented
Feb 28, 2026
- Remove unused QStandardPaths include
- Remove unused getProcIdExe function that was reading process executable paths
- Remove caller authorization check from setServiceEnableImpl method
- Remove unused dbusCallerPid and checkCaller methods
- Clean up related documentation comments Task: refactor(security): remove unused code and simplify service enable logic Task: https://pms.uniontech.com/task-view-386841.html
- Remove unused QStandardPaths include - Remove unused getProcIdExe function that was reading process executable paths - Remove caller authorization check from setServiceEnableImpl method - Remove unused dbusCallerPid and checkCaller methods - Clean up related documentation comments Task: refactor(security): remove unused code and simplify service enable logic Task: https://pms.uniontech.com/task-view-386841.html
deepin pr auto review代码审查报告概述这次修改移除了 代码审查意见1. 安全性问题(严重)问题描述: 改进建议:
2. 代码逻辑问题问题描述:
改进建议: bool SystemDBusServer::checkCaller() const
{
if (!calledFromDBus()) {
return false;
}
qint64 callerPid = dbusCallerPid();
QString callerExe = getProcIdExe(callerPid);
// 使用更可靠的验证方式,例如检查进程的命令行参数
QFile cmdLineFile(QString("/proc/%1/cmdline").arg(callerPid));
if (!cmdLineFile.open(QIODevice::ReadOnly)) {
return false;
}
QByteArray cmdline = cmdLineFile.readAll();
cmdLineFile.close();
// 检查命令行是否包含预期的程序名
if (!cmdline.contains("deepin-system-monitor")) {
return false;
}
// 可以添加额外的验证,如检查进程的启动时间、用户等
return true;
}3. 代码性能问题问题描述: 改进建议: 4. 代码质量建议问题描述:
改进建议:
5. 替代方案建议如果需要更安全的调用者验证机制,可以考虑以下方案:
bool SystemDBusServer::checkCaller() const
{
if (!calledFromDBus()) {
return false;
}
// 使用 Polkit 检查调用者是否有权限
PolkitQt1::Authority::Result result;
result = PolkitQt1::Authority::instance()->checkAuthorizationSync(
"com.deepin.systemmonitor.manage-services",
PolkitQt1::UnixProcessSubject(dbusCallerPid()),
PolkitQt1::Authority::AllowUserInteraction);
return result == PolkitQt1::Authority::Yes;
}
总结这次修改移除了调用者验证机制,虽然简化了代码,但引入了严重的安全风险。建议:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: KT-lcz, max-lvs, pppanghu77 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |