From f03c4cc45c683196bb4ad74d015853d8407d9b10 Mon Sep 17 00:00:00 2001 From: zhaoyingzhen Date: Fri, 11 Sep 2026 10:25:03 +0800 Subject: [PATCH] fix: remove unsafe Bluetooth D-Bus data exposure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the path-based BluetoothGetDeviceTechnologies method from the system daemon and keep DebugInfo compatible while returning no adapter or device data. Pms: BUG-370875, BUG-370897 删除系统守护进程中存在路径拼接风险的 BluetoothGetDeviceTechnologies 接口,并保留 DebugInfo 的 D-Bus 兼容签名但不再返回适配器和设备敏感信息。 Change-Id: I4b9e1a61c3c1cfd5245ca7f7ed97a6ff8097e4cb --- bin/dde-system-daemon/bluetooth.go | 42 --------------- bin/dde-system-daemon/bluetooth_test.go | 52 ------------------- .../exported_methods_auto.go | 6 --- .../doBluetoothGetDeviceTechnologies/info1 | 2 - bluetooth1/bluetooth_ifc.go | 4 +- system/bluetooth1/bluetooth_ifc.go | 8 +-- system/bluetooth1/bluetooth_ifc_test.go | 19 +++++++ 7 files changed, 27 insertions(+), 106 deletions(-) delete mode 100644 bin/dde-system-daemon/bluetooth.go delete mode 100644 bin/dde-system-daemon/bluetooth_test.go delete mode 100644 bin/dde-system-daemon/testdata/doBluetoothGetDeviceTechnologies/info1 create mode 100644 system/bluetooth1/bluetooth_ifc_test.go diff --git a/bin/dde-system-daemon/bluetooth.go b/bin/dde-system-daemon/bluetooth.go deleted file mode 100644 index 1fa84f77b..000000000 --- a/bin/dde-system-daemon/bluetooth.go +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -package main - -import ( - "fmt" - "path/filepath" - - dbus "github.com/godbus/dbus/v5" - "github.com/linuxdeepin/go-lib/dbusutil" - "github.com/linuxdeepin/go-lib/keyfile" -) - -const ( - bluetoothPrefixDir = "/var/lib/bluetooth" - - kfSectionGeneral = "General" - kfKeyTechnologies = "SupportedTechnologies" -) - -func (*Daemon) BluetoothGetDeviceTechnologies(adapter, device string) (technologies []string, busErr *dbus.Error) { - var filename = filepath.Join(bluetoothPrefixDir, adapter, device, "info") - if !filepath.HasPrefix(filename, bluetoothPrefixDir) { - return nil, dbusutil.ToError(fmt.Errorf("invaild adapter: [%s] device: [%s]", adapter, device)) - } - technologies, err := doBluetoothGetDeviceTechnologies(filename) - if err != nil { - return nil, dbusutil.ToError(err) - } - return technologies, nil -} - -func doBluetoothGetDeviceTechnologies(filename string) ([]string, error) { - var kf = keyfile.NewKeyFile() - err := kf.LoadFromFile(filename) - if err != nil { - return nil, fmt.Errorf("can't parse file: %s", filename) - } - return kf.GetStringList(kfSectionGeneral, kfKeyTechnologies) -} diff --git a/bin/dde-system-daemon/bluetooth_test.go b/bin/dde-system-daemon/bluetooth_test.go deleted file mode 100644 index b2fce07d0..000000000 --- a/bin/dde-system-daemon/bluetooth_test.go +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -package main - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func Test_doBluetoothGetDeviceTechnologies(t *testing.T) { - type args struct { - filename string - } - tests := []struct { - name string - args args - want []string - wantErr bool - }{ - { - name: "doBluetoothGetDeviceTechnologies", - args: args{ - filename: "./testdata/doBluetoothGetDeviceTechnologies/info1", - }, - want: []string{"abc", "ccc"}, - wantErr: false, - }, - { - name: "doBluetoothGetDeviceTechnologies not exists", - args: args{ - filename: "./testdata/nonono", - }, - want: []string{}, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := doBluetoothGetDeviceTechnologies(tt.args.filename) - if tt.wantErr { - assert.NotNil(t, err) - return - } - - assert.Nil(t, err) - assert.ElementsMatch(t, tt.want, got) - }) - } -} diff --git a/bin/dde-system-daemon/exported_methods_auto.go b/bin/dde-system-daemon/exported_methods_auto.go index 6b2d9ee38..624b7dcec 100644 --- a/bin/dde-system-daemon/exported_methods_auto.go +++ b/bin/dde-system-daemon/exported_methods_auto.go @@ -8,12 +8,6 @@ import ( func (v *Daemon) GetExportedMethods() dbusutil.ExportedMethods { return dbusutil.ExportedMethods{ - { - Name: "BluetoothGetDeviceTechnologies", - Fn: v.BluetoothGetDeviceTechnologies, - InArgs: []string{"adapter", "device"}, - OutArgs: []string{"technologies"}, - }, { Name: "ClearTty", Fn: v.ClearTty, diff --git a/bin/dde-system-daemon/testdata/doBluetoothGetDeviceTechnologies/info1 b/bin/dde-system-daemon/testdata/doBluetoothGetDeviceTechnologies/info1 deleted file mode 100644 index ea3ff982d..000000000 --- a/bin/dde-system-daemon/testdata/doBluetoothGetDeviceTechnologies/info1 +++ /dev/null @@ -1,2 +0,0 @@ -[General] -SupportedTechnologies=abc;ccc diff --git a/bluetooth1/bluetooth_ifc.go b/bluetooth1/bluetooth_ifc.go index b0c17cdb9..0e18e31fd 100644 --- a/bluetooth1/bluetooth_ifc.go +++ b/bluetooth1/bluetooth_ifc.go @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -291,6 +291,8 @@ func (b *Bluetooth) FeedPasskey(device dbus.ObjectPath, accept bool, passkey uin return nil } +// DebugInfo is retained for D-Bus compatibility. The system service returns +// an empty snapshot so this proxy cannot expose adapter or device details. func (b *Bluetooth) DebugInfo() (info string, busErr *dbus.Error) { logger.Info("dbus call DebugInfo") diff --git a/system/bluetooth1/bluetooth_ifc.go b/system/bluetooth1/bluetooth_ifc.go index 20ed831a8..f3768e777 100644 --- a/system/bluetooth1/bluetooth_ifc.go +++ b/system/bluetooth1/bluetooth_ifc.go @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -373,9 +373,11 @@ func (b *SysBluetooth) UnregisterAgent(sender dbus.Sender, agentPath dbus.Object return nil } +// DebugInfo is retained for D-Bus compatibility but no longer exposes +// adapter or device details. func (b *SysBluetooth) DebugInfo() (info string, busErr *dbus.Error) { - info = fmt.Sprintf("adapters: %s\ndevices: %s", marshalJSON(b.adapters), marshalJSON(b.devices)) - return info, nil + logger.Debug("dbus call DebugInfo") + return "", nil } // ClearUnpairedDevice will remove all device in unpaired list diff --git a/system/bluetooth1/bluetooth_ifc_test.go b/system/bluetooth1/bluetooth_ifc_test.go new file mode 100644 index 000000000..bf9d4daae --- /dev/null +++ b/system/bluetooth1/bluetooth_ifc_test.go @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +package bluetooth + +import "testing" + +func TestDebugInfoDoesNotExposeBluetoothDetails(t *testing.T) { + b := &SysBluetooth{} + + info, err := b.DebugInfo() + if err != nil { + t.Fatalf("DebugInfo returned an unexpected error: %v", err) + } + if want := ""; info != want { + t.Fatalf("DebugInfo returned %q, want %q", info, want) + } +}