Skip to content

Security fixes#98

Open
bradsp wants to merge 5 commits intomainfrom
Security-Fixes
Open

Security fixes#98
bradsp wants to merge 5 commits intomainfrom
Security-Fixes

Conversation

@bradsp
Copy link
Owner

@bradsp bradsp commented Sep 16, 2025

This pull request updates all database and logging configuration values across the solution to use environment variable placeholders instead of hardcoded values. This change improves security and flexibility by allowing different environments (development, test, production) to be configured without modifying source code.

Configuration modernization and environment variable support:

  • All database connection strings and related settings in App.config, .settings, and .Designer.cs files for both Lab PA WinForms UI and Lab Patient Accounting Job Scheduler projects now use placeholders (e.g., ${DB_SERVER}, ${DB_NAME}) instead of hardcoded values. This includes production, test, and logging databases. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19]

  • All NLog database target connection strings across projects are updated to use environment variable placeholders for server, database, username, and password, supporting secure and dynamic logging configuration. [1] [2] [3]

Application logic and UI updates:

  • The main menu in LabBillingConsole/Program.cs now displays generic database names ("Production Database", "Test Database") and fetches server/database names from environment variables, improving clarity and supporting dynamic configuration. [1] [2]

  • The Tag property for the billing reports menu item in AuditReportsForm.Designer.cs is updated to use environment variable placeholders for server names, supporting flexible server selection in the UI.

These changes collectively support better configuration management and deployment practices.

bradsp and others added 4 commits September 16, 2025 15:14
Removed database server values from settings.
… server names

Co-authored-by: bradsp <5133841+bradsp@users.noreply.github.com>
…3-f608e6b6f962

Security: Remove hardcoded credentials and server names from configuration files
@bradsp bradsp requested a review from Copilot September 16, 2025 20:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves security by replacing hardcoded database credentials and server names with environment variable placeholders throughout the Lab Patient Accounting system configuration files. This change follows security best practices by removing sensitive information from source code and enabling environment-specific configuration management.

  • Replaced all hardcoded database credentials, server names, and database names with environment variable placeholders (e.g., ${DB_SERVER}, ${DB_PASSWORD})
  • Updated NLog database connection strings to use environment variables for secure logging configuration
  • Modified application code to retrieve configuration values from environment variables with fallback defaults

Reviewed Changes

Copilot reviewed 12 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
SECURITY_CONFIGURATION_REMEDIATION.md Documentation detailing security remediation changes and required environment variables
Multiple .settings files Database configuration values replaced with environment variable placeholders
Multiple NLog.config files Logging database connection strings updated to use environment variables
Multiple App.config files Application configuration updated with environment variable placeholders
LabBillingConsole/Program.cs Menu display and database selection logic updated to use environment variables
Files not reviewed (4)
  • Lab PA WinForms UI/Legacy Forms/AuditReportsForm.Designer.cs: Language not supported
  • Lab PA WinForms UI/Properties/Settings.Designer.cs: Language not supported
  • Lab Patient Accounting Job Scheduler/Settings.Designer.cs: Language not supported
  • LabBillingService/Properties/Settings.Designer.cs: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

<target xsi:type="Database"
name="dbTarget"
connectionString="Data Source=WTHMCLBILL;Initial Catalog=NLog;Integrated Security=true;Encrypt=false;Trust Server Certificate=true"
connectionString="Data Source=${LOG_DB_SERVER};Initial Catalog=${LOG_DB_NAME};Integrated Security=true;Encrypt=false;Trust Server Certificate=true"
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The environment variable ${LOG_DB_SERVER} is inconsistent with other logging configurations that use ${DB_SERVER}. This inconsistency could lead to configuration errors. Consider using ${DB_SERVER} to match the pattern used in other NLog.config files.

Suggested change
connectionString="Data Source=${LOG_DB_SERVER};Initial Catalog=${LOG_DB_NAME};Integrated Security=true;Encrypt=false;Trust Server Certificate=true"
connectionString="Data Source=${DB_SERVER};Initial Catalog=${LOG_DB_NAME};Integrated Security=true;Encrypt=false;Trust Server Certificate=true"

Copilot uses AI. Check for mistakes.
cursor[bot]

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
// Get server and database names from environment variables or use defaults
string defaultServer = Environment.GetEnvironmentVariable("DB_SERVER") ?? "${DB_SERVER}";
string prodDbName = Environment.GetEnvironmentVariable("PROD_DB_NAME") ?? "${PROD_DB_NAME}";
string testDbName = Environment.GetEnvironmentVariable("TEST_DB_NAME") ?? "${TEST_DB_NAME}";
Copy link

Choose a reason for hiding this comment

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

Bug: Environment Variable Fallback Uses Placeholder Strings

When environment variables are not set, the fallback logic uses literal placeholder strings (e.g., ${DB_SERVER}) for server and database names. This causes database connection failures as the application attempts to connect to servers literally named after these placeholders.

Fix in Cursor Fix in Web

[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("NLog")]
[global::System.Configuration.DefaultSettingValueAttribute("${TEST_LOG_DB_NAME}")]
Copy link

Choose a reason for hiding this comment

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

Bug: Configuration System Fails to Expand Environment Variables

The .NET Framework configuration system does not natively expand environment variable placeholders like ${VAR} in App.config or DefaultSettingValueAttribute. This causes the application to use these placeholders as literal strings, leading to database connection failures across the WinForms UI, Job Scheduler, and Billing Service.

Additional Locations (4)

Fix in Cursor Fix in Web

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.

3 participants