fix(security): id-form credential references match by id only; id-shaped driver names refused (#849 review)
A driver named 'drv' (env form DRV) matched every sibling's id-form variable env:<PREFIX>DRV_<12HEX>_... as 'another instance', breaking the recommended id convention fleet-wide - including for a name that pre-dates the rule. ReferenceNames is split into ReferenceNamesId / ReferenceNamesName; a reference whose instance part is id-shaped (secret: DRV-<12 hex>, env: DRV_<12 HEX>[_...]) is matched by id only. DescribeNameChangeProblemsAsync also refuses new names whose env form is DRV or starts with an id form (IsReservedInstanceName) at create, /raw rename and config-modal update. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,7 @@ public static class DriverInstanceIdentities
|
||||
/// <summary>
|
||||
/// lmxopcua#848: the problems of giving a driver the name <paramref name="newName"/> (create, or a rename via the
|
||||
/// /raw rename or the driver config modal). Two rules, both about a name being the instance part of a stored
|
||||
/// credential reference (<see cref="DriverCredentialPolicy.ReferenceNames"/>):
|
||||
/// credential reference (<see cref="DriverCredentialPolicy.ReferenceNamesName"/>):
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <b>Claim</b> — the new name may not be named by a reference STORED on another same-type driver (its
|
||||
@@ -123,6 +123,19 @@ public static class DriverInstanceIdentities
|
||||
if (!DriverCredentialPolicy.TryGet(driverType, out var rules)) return [];
|
||||
if (currentName is not null && string.Equals(currentName, newName, StringComparison.OrdinalIgnoreCase)) return [];
|
||||
|
||||
// #849 review: a name in the system-generated id form (env form 'DRV' or 'DRV_<12 HEX>…') would shadow the id
|
||||
// convention every driver's own references are recommended to use. The matcher already ignores such a name for
|
||||
// id-shaped references (so a pre-existing one breaks nothing); this keeps new ones from being created at all.
|
||||
if (DriverCredentialPolicy.IsReservedInstanceName(newName))
|
||||
{
|
||||
return
|
||||
[
|
||||
$"The name '{newName}' has the form of a system-generated driver id ('{DriverCredentialPolicy.DriverIdPrefix}' or "
|
||||
+ $"'{DriverCredentialPolicy.DriverIdPrefix}-<12 hex>…'), which {rules.Scope.Label} credential references use to name a "
|
||||
+ "driver by its id — choose another name (lmxopcua#848/#849).",
|
||||
];
|
||||
}
|
||||
|
||||
// Same shape as LoadAsync: the type filter stays client-side (case-insensitive), the device read is a plain IN.
|
||||
var drivers = (await db.DriverInstances.AsNoTracking()
|
||||
.Select(d => new { d.DriverInstanceId, d.Name, d.DriverType, d.DriverConfig })
|
||||
@@ -154,7 +167,7 @@ public static class DriverInstanceIdentities
|
||||
var where = device is null ? "" : $" device '{device}'";
|
||||
foreach (var reference in DriverCredentialPolicy.CollectInstanceReferences(driverType, json))
|
||||
{
|
||||
if (!own && DriverCredentialPolicy.ReferenceNames(reference, newName))
|
||||
if (!own && DriverCredentialPolicy.ReferenceNamesName(reference, newName))
|
||||
{
|
||||
problems.Add(
|
||||
$"The name '{newName}' is the instance part of the credential reference {reference.FieldPath} on "
|
||||
@@ -163,9 +176,9 @@ public static class DriverInstanceIdentities
|
||||
+ "Choose another name, or move that reference first (lmxopcua#848).");
|
||||
}
|
||||
else if (own && currentName is not null
|
||||
&& DriverCredentialPolicy.ReferenceNames(reference, currentName)
|
||||
&& !DriverCredentialPolicy.ReferenceNames(reference, ownDriverInstanceId)
|
||||
&& !DriverCredentialPolicy.ReferenceNames(reference, newName))
|
||||
&& DriverCredentialPolicy.ReferenceNamesName(reference, currentName)
|
||||
&& !DriverCredentialPolicy.ReferenceNamesId(reference, ownDriverInstanceId)
|
||||
&& !DriverCredentialPolicy.ReferenceNamesName(reference, newName))
|
||||
{
|
||||
problems.Add(
|
||||
$"This driver's credential reference {reference.FieldPath}{where} is named after its current name "
|
||||
|
||||
Reference in New Issue
Block a user