Skip to content

Commit f0acf50

Browse files
authored
feat(core): validate duplicated capability identifier (#10858)
having duplicate capability identifier lead to unexpected behavior because one of the capabilities gets ignored. With this change the build script now fails when this happens.
1 parent ecc5362 commit f0acf50

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": patch:enhance
3+
---
4+
5+
Validate duplicate capability identifier.

‎crates/tauri-utils/src/acl/build.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,20 @@ pub fn parse_capabilities(
135135
{
136136
match CapabilityFile::load(&path)? {
137137
CapabilityFile::Capability(capability) => {
138+
if capabilities_map.contains_key(&capability.identifier) {
139+
return Err(Error::CapabilityAlreadyExists {
140+
identifier: capability.identifier,
141+
});
142+
}
138143
capabilities_map.insert(capability.identifier.clone(), capability);
139144
}
140145
CapabilityFile::List(capabilities) | CapabilityFile::NamedList { capabilities } => {
141146
for capability in capabilities {
147+
if capabilities_map.contains_key(&capability.identifier) {
148+
return Err(Error::CapabilityAlreadyExists {
149+
identifier: capability.identifier,
150+
});
151+
}
142152
capabilities_map.insert(capability.identifier.clone(), capability);
143153
}
144154
}

‎crates/tauri-utils/src/acl/mod.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ pub enum Error {
126126
/// Permission identifier.
127127
permission: String,
128128
},
129+
130+
/// Capability with the given identifier already exists.
131+
#[error("capability with identifier `{identifier}` already exists")]
132+
CapabilityAlreadyExists {
133+
/// Capability identifier.
134+
identifier: String,
135+
},
129136
}
130137

131138
/// Allowed and denied commands inside a permission.

0 commit comments

Comments
 (0)