Skip to content

Fix SyncProductFilter and SyncCAFilter having no effect - #66

Open
Pichatorn-A4K wants to merge 1 commit into
Keyfactor:mainfrom
Pichatorn-A4K:fix/sync-filters-are-no-ops
Open

Pichatorn-A4K wants to merge 1 commit into
Keyfactor:mainfrom
Pichatorn-A4K:fix/sync-filters-are-no-ops

Conversation

@Pichatorn-A4K

Copy link
Copy Markdown

Two independent problems in the sync-filter area, both of which make a configured filter silently do
something other than what it says. Found while auditing the shipped 2.4.1 assembly; both are also
present in 2.4.2-rc.0.

1. SyncProductFilter never filters

GetAllConnectorCertsForOrder has three filter blocks in a row. The SyncCAFilter and Division
blocks both return null when the order does not match; the product block logs and then falls
through
:

if (productIds != null && productIds.Count > 0 && !productIds.Contains(orderResponse.product.name_id.ToString()))
{
    _logger.LogTrace($"Found order ID {orderId} that does not match Product filter. ... Skipping...");
}   // <- no return, so the order is synchronized anyway

It appears to work on a full sync only because ListAllCertificateOrders also sends
filters[product_name_id] to DigiCert. On an incremental sync the filter is not applied at all,
because status-changes takes no product filter — so out-of-scope products reach Command while the
log claims they were skipped.

2. SyncCAFilter never matches a lower-case value

caList.ForEach(c => c.ToUpper());

String.ToUpper() returns a new string; the result is discarded, so the list is never upper-cased.
The comparison downstream is:

!caFilterIds.Contains(orderResponse.certificate.ca_cert.Id.ToUpper())

The DigiCert side is upper-cased, so a CA ID entered in lower case matches nothing and every
order is skipped — the sync returns zero certificates with no error, only a trace line per order.

CertCentralConfig.SyncCAs also materialises a fresh List<string> on each access, so an in-place
mutation could not have persisted even if ToUpper() had mutated. The fix assigns the projection
back, and additionally trims and drops empty entries so a trailing comma in the config value does not
produce an entry that can never match.

Verification

Driving Synchronize() offline against a fake CertCentralClient:

  • a lower-case SyncCAFilter matches the order (and a genuinely different filter value still
    excludes it, so the test cannot pass for the wrong reason);
  • SyncProductFilter excludes a non-matching product and keeps a matching one.

Reverting either change makes the corresponding test fail. The tests are not in this PR because the
repository has no test project; happy to contribute the harness separately.

🤖 Generated with Claude Code

Two separate problems in the same area, both of which make a configured
filter silently do the wrong thing.

SyncProductFilter: the product-filter block in
GetAllConnectorCertsForOrder logs 'Skipping...' but is missing the
'return null' that the SyncCAFilter and Division blocks immediately above
it both have, so execution falls through and the order is synchronized
anyway. It appears to work on a full sync only because
ListAllCertificateOrders also passes filters[product_name_id] to
DigiCert; on an incremental sync (status-changes takes no product filter)
it is not enforced at all.

SyncCAFilter: 'caList.ForEach(c => c.ToUpper())' discards its result,
because String.ToUpper returns a new string rather than mutating in
place, so the list is never upper-cased. The comparison further down is
against 'orderResponse.certificate.ca_cert.Id.ToUpper()', i.e. the
DigiCert side IS upper-cased, so a filter entered in lower case matches
nothing and the sync returns zero certificates with no error - only a
trace line. (CertCentralConfig.SyncCAs also materialises a new List on
each access, so an in-place mutation could not have persisted either.)
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.

1 participant