Skip to content

Potential fix for code scanning alert no. 113: Log entries created from user input#261

Open
aurelianware wants to merge 1049 commits into
mainfrom
alert-autofix-113
Open

Potential fix for code scanning alert no. 113: Log entries created from user input#261
aurelianware wants to merge 1049 commits into
mainfrom
alert-autofix-113

Conversation

@aurelianware
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/aurelianware/cloudhealthoffice/security/code-scanning/113

In general, to fix log-forging issues, user-controlled values should be sanitized before being logged, at least by removing newline and carriage-return characters (and optionally other control characters). This ensures a malicious header value cannot inject extra log lines or otherwise alter log structure.

For this case, the single best fix with minimal functional change is to sanitize TenantId at the controller boundary, where it enters the system, and then log and propagate the sanitized value throughout the services and repository. That way, any downstream logging involving tenantId or entities whose TenantId is derived from it (like SponsorEntity.TenantId) will automatically use the safe version. Specifically:

  • In EnrollmentController.ImportEnrollment, after checking that tenantId is not null or empty, create a sanitized version that strips \r and \n characters (and optionally trims whitespace), e.g. var safeTenantId = tenantId.Replace("\r", "").Replace("\n", "");.
  • Use safeTenantId in the _logger.LogInformation call in the controller.
  • Pass safeTenantId to _importService.ImportEnrollmentAsync(...) instead of the raw tenantId.

No changes are required to EnrollmentImportService or EnrollmentRepository to maintain existing functionality; they will continue to receive the tenantId argument and set SponsorEntity.TenantId the same way, but now it will already be sanitized. This directly addresses the CodeQL finding because the logged sponsor.TenantId in EnrollmentRepository.CreateSponsorAsync can no longer contain line breaks injected by an attacker.

Concretely:

  • Edit services/enrollment-import-service/Controllers/EnrollmentController.cs within ImportEnrollment:
    • Introduce a safeTenantId variable after the null/empty check.
    • Use safeTenantId in both the LogInformation call and the service call.
  • No import changes are needed, as we use only string.Replace, which is in System and already available.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Copilot AI and others added 30 commits January 28, 2026 10:43
…ON.parse DoS

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
- Add Access-Control-Max-Age header to eligibility-service for consistency
- Document CORS wildcard + credentials limitation in both services
- Change wildcard CORS to echo origin (instead of '*') for credential compatibility
- Add Vary: Origin header for proper caching behavior

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
…ng-warnings

Fix code scanning security vulnerabilities (17+ alerts)
…olled format string

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
…service

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
Fix format string injection vulnerabilities in error logging
Potential fix for code scanning alert no. 17: Use of externally-controlled format string
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
Potential fix for code scanning alert no. 11: Workflow does not contain permissions
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
… demographics

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
… gender, and cityIndex

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
Potential fix for code scanning alert no. 14: Insecure randomness
…domInt for PHI security

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
Replace remaining Math.random() with secureRandomInt in patient demographics
… phone, address, maritalStatus)

Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
Extend secure randomness to all PHI fields in patient generator
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
Potential fix for code scanning alert no. 12: Workflow does not contain permissions
aurelianware and others added 16 commits February 6, 2026 20:33
…anization, contact, billing, and contract tracking
…nsurance, benefits library, and exclusions management
… usage stats and benefit plan assignment capability
… Pipeline

- README.md: Add Provider UI and 837 pipeline to core capabilities
- FEATURES.md: Add Provider Network Management section (13 providers, 6-tab details)
- FEATURES.md: Add 837 Claims section (Argo Workflows + Kafka pipeline)
- ARCHITECTURE.md: Update microservices count to 10, add 6 utility containers
- DEPLOYMENT.md: Add Container Image Build & Deployment section (18 images)
Comprehensive assessment covering:
- Technical infrastructure: 75% complete (strong foundation)
- Business readiness: 25% complete (missing critical components)
- 8-12 week staged rollout plan (Beta → Limited GA → Full GA)
- Critical gaps: tenant management, billing, legal docs, portal integration
- Recommended MVS: 4 sprints to first paying customer
- Budget estimate: -75k over 12 weeks, ~3.6 FTE
- Success metrics: 3 beta customers by week 4, k MRR by week 8

Priority 1 next steps: Stripe setup, BAA template, tenant management API
New microservice for multi-tenant SaaS management:

Tenant Management:
- CRUD operations for health plan tenants
- Automatic tenant ID generation (e.g., blueshield-ca-a1b2c3d4)
- Status management (pending, active, suspended, terminated)
- Multi-tier support (Starter, Professional, Enterprise)
- Configuration management (modules, clearinghouse settings)

API Key Management:
- Cryptographically secure key generation (cho_xxxx...)
- SHA256 hashing (never store plain-text)
- Scoped permissions (claims:read, claims:write)
- Expiration support and revocation
- Last used tracking

Usage Tracking:
- Monthly metrics (claims, prior auths, eligibility, API calls)
- Automatic monthly reset
- Storage tracking (GB)
- Tier limit enforcement ready

Stripe Billing Integration:
- Customer creation in Stripe
- Subscription managemen
New microservice for multi-tenant SaaS management:

Tenant Management:
- CRUD operations for health plan tenants
- Automatic tenant ID generation (e.g., blueshield-ca-a1b2c3d4)
- Status managemets
Tenant Management:
- CRUD operations for health eme- CRUD operationsan- Automatic tenant ID generation (e.g., g - Status management (pending, active, suspended, terminated)
-
-- Multi-tier support (Starter, Professional, Enterprise)
- .n- Configuration management (modules, clearinghouse settym
API Key Management:
- Cryptographically secure key generatock- Cryptographicallau- SHA256 hashing (never store plain-text)
- Scoped perct- Scoped permissions (claims:read, claimxt- Expiration support and revocation
- Last usedflow
- X12 834 parser (Node.js) for benefit enrollment EDI files
- Enrollment import service (.NET 8) with Cosmos DB integration
- Argo CronWorkflow for automated SFTP processing
- Kubernetes deployment with HPA (2-10 replicas)
- Sample 834 test file and comprehensive documentation

Handles member additions, changes, and terminations with multi-tenant isolation.
- Add validation for test-x12-834-enrollment-sample.edi
- Add microservices structure validation (enrollment-import-service)
- Add Node.js container validation (x12-834-parser)
- Add Argo Workflow validation (x12-834-enrollment-import.yaml)
- Update test summary to reflect new validations
- Add 834 transaction type definition
- Accept 'BE' functional identifier for enrollment (in addition to 'HI' for claims)
- Update parameter validation to include 834
- Update documentation to reflect 834 support

Fixes smoke test failures when validating test-x12-834-enrollment-sample.edi
- Add exclusions for code comments about validation (exists, verify, validate, check, ensure)
- Allow internal Kubernetes cluster URLs (svc.cluster.local, localhost) for UnencryptedPHI check
- These are not actual PHI exposures - just metadata and internal service communication

Resolves false positive smoke test failures in security scan.
- Add WebSocket support to portal ingress (proxy upgrade headers)
- Enable sticky sessions with cookie-based affinity (required for Blazor Server with multiple replicas)
- Add nginx ConfigMap with WebSocket upgrade header mapping
- Increase session affinity timeout to 3 hours for long-running Blazor sessions
- Configure proxy buffers for SignalR message handling

Fixes WebSocket connection failures: 'No Connection with that ID' 404 errors
WebSocket support is still enabled via:
- websocket-services annotation
- proxy-http-version 1.1
- nginx ConfigMap with upgrade header mapping
…om user input

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
aurelianware and others added 2 commits February 7, 2026 01:01
…vices/claims-scrubbing-service/azure/storage-blob-12.30.0

Bump @azure/storage-blob from 12.29.1 to 12.30.0 in /services/claims-scrubbing-service
…om user input

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: aurelianware <markus@aurelianware.com>
@aurelianware aurelianware marked this pull request as ready for review February 7, 2026 08:08
Copilot AI review requested due to automatic review settings February 7, 2026 08:08
Copy link
Copy Markdown
Contributor

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

Mitigates code-scanning finding #113 (log-forging via user-controlled input) by sanitizing request-derived values before writing them to structured logs in the enrollment import API.

Changes:

  • Sanitize tenantId from X-Tenant-ID header to strip \r/\n, and propagate the sanitized value downstream.
  • Sanitize enrollment.FileName before logging to prevent log line injection.
  • Update controller logging/service call to use sanitized values.

Comment on lines 27 to +31
return BadRequest("X-Tenant-ID header is required");
}

// Sanitize tenantId to prevent log forging by removing line breaks
var safeTenantId = tenantId.Replace("\r", string.Empty).Replace("\n", string.Empty);
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

tenantId is validated before sanitization, so a header value containing only CR/LF (or whitespace + CR/LF) will pass IsNullOrEmpty, be sanitized to an empty string, and then be used for logging and passed downstream as the tenant context. Re-validate after sanitization (or reject when tenantId contains CR/LF/control chars) and return BadRequest if the resulting tenant id is empty/whitespace.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants