Skip to content

Code Review Bench PR #64970 - Ensure SSL_CERT_DIR messages are always shown and check for existing value#3

Closed
ketkarameya wants to merge 6 commits intobase_pr_64970_20260125_1452from
corrupted_pr_64970_20260125_1452
Closed

Code Review Bench PR #64970 - Ensure SSL_CERT_DIR messages are always shown and check for existing value#3
ketkarameya wants to merge 6 commits intobase_pr_64970_20260125_1452from
corrupted_pr_64970_20260125_1452

Conversation

@ketkarameya
Copy link

@ketkarameya ketkarameya commented Feb 10, 2026

Code Review Bench PR dotnet#64970 - Ensure SSL_CERT_DIR messages are always shown and check for existing value

Benchmark PR for Gitar evaluation

Original PR: agentic-review-benchmarks#3

Ensures SSL_CERT_DIR messages are always displayed and checks for existing values.



Summary by Gitar

  • SSL configuration messaging improvements:
    • Changed event listener to always show LogAlways-level messages without requiring verbose flag
    • Messages now display with proper environment variable syntax using quotes
  • Added SSL_CERT_DIR existence checking:
    • Detects when certificate directory is already included in existing SSL_CERT_DIR environment variable
    • Provides appropriate messaging for pre-configured vs. new setup scenarios
  • Code modernization:
    • Converted NssDb primary constructor to traditional constructor with backing fields

This will update automatically on new commits.

if (!string.IsNullOrEmpty(existingSslCertDir))
{
var existingDirs = existingSslCertDir.Split(Path.PathSeparator);
var certDirFullPath = Path.GetFullPath(prettyCertDir);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Bug: Path.GetFullPath(prettyCertDir) breaks when path contains literal $HOME

When certDir starts with the home directory, prettyCertDir is set to a display-friendly string like $HOME/.aspnet/dev-certs/trust (line 354-356). Then on line 365, Path.GetFullPath(prettyCertDir) is called on this value.

Path.GetFullPath does NOT expand shell variables — $HOME is treated as a literal directory name. On Unix, this resolves to something like /current/working/dir/$HOME/.aspnet/dev-certs/trust, which will never match any real path in SSL_CERT_DIR.

This means the certificate directory inclusion check will always fail for users whose cert dir is under their home directory (the common case), causing spurious "suggest appending" messages even when SSL_CERT_DIR is already correctly configured.

Fix: Use certDir (the actual filesystem path) instead of prettyCertDir for the Path.GetFullPath call:

var certDirFullPath = Path.GetFullPath(certDir);

prettyCertDir should only be used for display/logging purposes, not for path resolution.

Was this helpful? React with 👍 / 👎

Suggested change
var certDirFullPath = Path.GetFullPath(prettyCertDir);
var certDirFullPath = Path.GetFullPath(certDir);
  • Apply suggested fix


try
{
return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.OrdinalIgnoreCase);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: Case-insensitive path comparison is incorrect on Unix filesystems

On line 375, path comparison uses StringComparison.OrdinalIgnoreCase:

return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.OrdinalIgnoreCase);

Unix filesystems (ext4, XFS, btrfs, etc.) are case-sensitive by default. /home/User/certs and /home/user/certs are different directories on Unix. Using case-insensitive comparison can produce false positives — the code would incorrectly conclude that the cert directory is already in SSL_CERT_DIR when it actually isn't (just a different path with different casing).

Since this code is in UnixCertificateManager (Unix-only), the comparison should use StringComparison.Ordinal to match the filesystem's case sensitivity. The original code was correct in this regard.

The PR context mentions that "file systems can have paths with different case representations" but on Unix this would mean they're genuinely different paths. Only macOS HFS+ is case-insensitive, and even then Path.GetFullPath preserves the original casing.

Was this helpful? React with 👍 / 👎

Suggested change
return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.OrdinalIgnoreCase);
return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.Ordinal);
  • Apply suggested fix

hasValidSslCertDir = false;
}

sawTrustFailure = !hasValidSslCertDir;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: sawTrustFailure overwrite can mask prior NSS DB trust failures

Line 408 unconditionally assigns sawTrustFailure = !hasValidSslCertDir, which can overwrite a previous true value set by NSS DB trust failures (lines 295, 322, 328).

Scenario: NSS DB trust fails (sawTrustFailure = true), but OpenSSL trust succeeds and SSL_CERT_DIR is correctly configured (hasValidSslCertDir = true). The assignment sawTrustFailure = false masks the NSS failure, and the method returns TrustLevel.Full instead of TrustLevel.Partial.

Fix: Use |= to accumulate failures rather than overwrite:

sawTrustFailure |= !hasValidSslCertDir;

This ensures that if any prior trust step failed, the overall result still reflects partial trust.

Was this helpful? React with 👍 / 👎

Suggested change
sawTrustFailure = !hasValidSslCertDir;
sawTrustFailure |= !hasValidSslCertDir;
  • Apply suggested fix

Copy link

@gitar-bot-staging gitar-bot-staging bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This PR is blocked due to unresolved code review findings.

Configure merge blocking · Maintainers can dismiss this review. Gitar never approves changes.

@gitar-bot-staging
Copy link

gitar-bot-staging bot commented Feb 10, 2026

Note

Gitar has paused automatic reviews. Comment "Gitar review" to trigger a review manually.

Code Review 🚫 Blocked 0 resolved / 3 findings

Critical bug in path resolution using prettyCertDir (contains literal $HOME), plus sawTrustFailure overwrite that can mask NSS DB failures and inappropriate case-insensitive path comparison on Unix.

🚨 Bug: Path.GetFullPath(prettyCertDir) breaks when path contains literal $HOME

📄 src/Shared/CertificateGeneration/UnixCertificateManager.cs:365

When certDir starts with the home directory, prettyCertDir is set to a display-friendly string like $HOME/.aspnet/dev-certs/trust (line 354-356). Then on line 365, Path.GetFullPath(prettyCertDir) is called on this value.

Path.GetFullPath does NOT expand shell variables — $HOME is treated as a literal directory name. On Unix, this resolves to something like /current/working/dir/$HOME/.aspnet/dev-certs/trust, which will never match any real path in SSL_CERT_DIR.

This means the certificate directory inclusion check will always fail for users whose cert dir is under their home directory (the common case), causing spurious "suggest appending" messages even when SSL_CERT_DIR is already correctly configured.

Fix: Use certDir (the actual filesystem path) instead of prettyCertDir for the Path.GetFullPath call:

var certDirFullPath = Path.GetFullPath(certDir);

prettyCertDir should only be used for display/logging purposes, not for path resolution.

Suggested fix
                var certDirFullPath = Path.GetFullPath(certDir);
⚠️ Bug: Case-insensitive path comparison is incorrect on Unix filesystems

📄 src/Shared/CertificateGeneration/UnixCertificateManager.cs:375

On line 375, path comparison uses StringComparison.OrdinalIgnoreCase:

return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.OrdinalIgnoreCase);

Unix filesystems (ext4, XFS, btrfs, etc.) are case-sensitive by default. /home/User/certs and /home/user/certs are different directories on Unix. Using case-insensitive comparison can produce false positives — the code would incorrectly conclude that the cert directory is already in SSL_CERT_DIR when it actually isn't (just a different path with different casing).

Since this code is in UnixCertificateManager (Unix-only), the comparison should use StringComparison.Ordinal to match the filesystem's case sensitivity. The original code was correct in this regard.

The PR context mentions that "file systems can have paths with different case representations" but on Unix this would mean they're genuinely different paths. Only macOS HFS+ is case-insensitive, and even then Path.GetFullPath preserves the original casing.

Suggested fix
                        return string.Equals(Path.GetFullPath(dir), certDirFullPath, StringComparison.Ordinal);
⚠️ Bug: sawTrustFailure overwrite can mask prior NSS DB trust failures

📄 src/Shared/CertificateGeneration/UnixCertificateManager.cs:408

Line 408 unconditionally assigns sawTrustFailure = !hasValidSslCertDir, which can overwrite a previous true value set by NSS DB trust failures (lines 295, 322, 328).

Scenario: NSS DB trust fails (sawTrustFailure = true), but OpenSSL trust succeeds and SSL_CERT_DIR is correctly configured (hasValidSslCertDir = true). The assignment sawTrustFailure = false masks the NSS failure, and the method returns TrustLevel.Full instead of TrustLevel.Partial.

Fix: Use |= to accumulate failures rather than overwrite:

sawTrustFailure |= !hasValidSslCertDir;

This ensures that if any prior trust step failed, the overall result still reflects partial trust.

Suggested fix
            sawTrustFailure |= !hasValidSslCertDir;
Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@kayagokalp
Copy link

Benchmark Evaluation Results

Ground Truth Bugs (Recall: 3/4 = 75.0%)

ID Severity Title Found?
GT-3-001 Critical Path.GetFullPath called on literal $HOME string that doesn't Yes
GT-3-002 Important Case-insensitive path comparison on Unix filesystem Yes
GT-3-003 Important Unconditional sawTrustFailure assignment overwrites previous Yes
GT-3-004 Critical LogAlways level change exposes Event 111 format string crash No

Extra Gitar Findings

File Line Valid Bug? Notes
(none) - - -

Summary

  • Recall: 75.0% (3/4)
  • Precision: 100.0% (3/3)
  • Precision counts ground truth matches + valid extra findings as true positives

@kayagokalp kayagokalp closed this Feb 25, 2026
@kayagokalp kayagokalp deleted the corrupted_pr_64970_20260125_1452 branch February 25, 2026 02:05
@kayagokalp kayagokalp restored the corrupted_pr_64970_20260125_1452 branch February 25, 2026 02:16
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.

4 participants