Skip to content

Security: xshopai/payment-service

.github/SECURITY.md

Security Policy

Overview

The Payment Service is a highly secure .NET 8 microservice responsible for payment processing, financial transactions, and payment method management within the xshopai platform. This service handles extremely sensitive financial data and must comply with the highest security standards including PCI DSS.

Supported Versions

We provide security updates for the following versions:

Version Supported
1.0.x
< 1.0

Security Features

PCI DSS Compliance

  • PCI DSS Level 1: Full compliance with payment card industry standards
  • Tokenization: No storage of actual payment card data
  • Encryption at Rest: AES-256 encryption for all sensitive data
  • Encryption in Transit: TLS 1.3 for all communications

Payment Security

  • Third-party Integration: Secure Stripe and PayPal integration
  • Payment Tokenization: Secure token-based payment processing
  • CVV Validation: Secure card verification without storage
  • Fraud Detection: Real-time fraud detection and prevention

.NET Security Framework

  • ASP.NET Core Security: Advanced security middleware
  • JWT Bearer Authentication: Secure service authentication
  • Entity Framework Core: Secure database operations
  • FluentValidation: Comprehensive payment data validation

Financial Data Protection

  • Field-level Encryption: Individual field encryption for sensitive data
  • Key Management: Azure Key Vault for encryption key management
  • Data Masking: PII masking in logs and responses
  • Secure Deletion: Cryptographic deletion of sensitive data

Transaction Security

  • Idempotency Keys: Prevent duplicate payment processing
  • Transaction Integrity: ACID compliance for financial operations
  • Audit Trail: Complete financial transaction audit logging
  • Reconciliation: Automated payment reconciliation processes

Security Best Practices

For Developers

  1. PCI DSS Configuration: Secure payment service setup

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=server;Database=PaymentService;Integrated Security=true;Encrypt=true;TrustServerCertificate=false"
      },
      "PaymentProviders": {
        "Stripe": {
          "SecretKey": "*** (use Azure Key Vault)",
          "PublishableKey": "pk_live_...",
          "WebhookSecret": "*** (use Azure Key Vault)"
        },
        "PayPal": {
          "ClientId": "*** (use Azure Key Vault)",
          "ClientSecret": "*** (use Azure Key Vault)",
          "Environment": "Live"
        }
      },
      "Security": {
        "EncryptionKey": "*** (use Azure Key Vault)",
        "TokenizationProvider": "Azure",
        "PciComplianceMode": true
      }
    }
  2. Payment Validation: Comprehensive payment data validation

    public class ProcessPaymentValidator : AbstractValidator<ProcessPaymentRequest>
    {
        public ProcessPaymentValidator()
        {
            RuleFor(x => x.Amount)
                .GreaterThan(0)
                .LessThan(1000000)
                .WithMessage("Invalid payment amount");
    
            RuleFor(x => x.Currency)
                .NotEmpty()
                .Length(3)
                .Matches("^[A-Z]{3}$")
                .WithMessage("Invalid currency code");
    
            RuleFor(x => x.PaymentToken)
                .NotEmpty()
                .Must(BeValidToken)
                .WithMessage("Invalid payment token");
    
            // Never validate actual card numbers - only tokens
            RuleFor(x => x.IdempotencyKey)
                .NotEmpty()
                .Must(BeValidGuid)
                .WithMessage("Invalid idempotency key");
        }
    }
  3. Secure Payment Processing: Safe payment handling

    public class PaymentService : IPaymentService
    {
        private readonly IPaymentTokenizer _tokenizer;
        private readonly IEncryptionService _encryption;
        private readonly IAuditLogger _auditLogger;
    
        public async Task<PaymentResult> ProcessPaymentAsync(ProcessPaymentRequest request)
        {
            // Validate idempotency
            if (await _repository.PaymentExistsAsync(request.IdempotencyKey))
            {
                return await _repository.GetPaymentByIdempotencyKeyAsync(request.IdempotencyKey);
            }
    
            // Log payment attempt (without sensitive data)
            await _auditLogger.LogPaymentAttemptAsync(new PaymentAuditEntry
            {
                CustomerId = request.CustomerId,
                Amount = request.Amount,
                Currency = request.Currency,
                PaymentMethod = MaskPaymentMethod(request.PaymentToken),
                Timestamp = DateTime.UtcNow
            });
    
            // Process payment with provider
            var result = await _paymentProvider.ProcessPaymentAsync(request);
    
            // Store only non-sensitive data
            await _repository.SavePaymentAsync(new Payment
            {
                Id = Guid.NewGuid(),
                CustomerId = request.CustomerId,
                Amount = request.Amount,
                Currency = request.Currency,
                Status = result.Status,
                ProviderTransactionId = result.TransactionId,
                IdempotencyKey = request.IdempotencyKey,
                CreatedAt = DateTime.UtcNow
            });
    
            return result;
        }
    }
  4. Encryption and Tokenization: Secure sensitive data handling

    // Field-level encryption for sensitive data
    public class EncryptedPaymentMethod
    {
        [Encrypted]
        public string MaskedCardNumber { get; set; } // Only last 4 digits
    
        [Encrypted]
        public string PaymentToken { get; set; } // Provider token
    
        public string PaymentType { get; set; } // "credit_card", "paypal", etc.
    
        // Never store actual card details
    }
    
    // Secure token generation
    public string GenerateSecureToken()
    {
        using var rng = RandomNumberGenerator.Create();
        var bytes = new byte[32];
        rng.GetBytes(bytes);
        return Convert.ToBase64String(bytes);
    }

For Deployment

  1. PCI DSS Environment:

    • Deploy in PCI DSS compliant infrastructure
    • Network segmentation and firewall rules
    • Regular vulnerability scanning
    • Penetration testing requirements
  2. Database Security:

    • SQL Server encryption at rest (TDE)
    • Always Encrypted for sensitive columns
    • Database firewall rules
    • Automated backup encryption
  3. Azure Security:

    • Azure Key Vault for all secrets
    • Managed Identity for authentication
    • Azure Security Center monitoring
    • Network Security Groups (NSGs)

Data Handling

Sensitive Data Categories

  1. Payment Data (PCI DSS Scope):

    • Payment tokens (never actual card data)
    • Masked payment method information
    • Payment processor transaction IDs
    • Payment status and metadata
  2. Financial Information:

    • Transaction amounts and currencies
    • Refund and chargeback data
    • Fee calculations and splits
    • Financial reconciliation data
  3. Customer Financial Data:

    • Payment method preferences
    • Payment history and patterns
    • Billing information references
    • Fraud detection metadata

Data Protection Measures

  • Tokenization: Replace sensitive data with secure tokens
  • Encryption at Rest: AES-256 encryption for all stored data
  • Encryption in Transit: TLS 1.3 for all communications
  • Data Masking: Sensitive data masking in logs and APIs
  • Secure Deletion: Cryptographic deletion of expired data

Data Retention (PCI DSS Compliant)

  • Payment transaction records: 7 years (financial compliance)
  • Payment tokens: Until customer removes payment method
  • Audit logs: 1 year minimum (PCI DSS requirement)
  • Fraud detection data: 2 years (security analysis)
  • NO storage of actual payment card data

Vulnerability Reporting

Reporting Security Issues

Payment service vulnerabilities require immediate attention:

  1. Do NOT open a public issue
  2. Do NOT test with real payment data
  3. Email our security team at: security@xshopai.com
  4. Mark as: "URGENT PCI DSS SECURITY ISSUE"

Critical Security Areas

  • Payment data exposure or storage
  • Payment processing manipulation
  • PCI DSS compliance violations
  • Financial calculation errors
  • Authentication bypass for payment functions

Response Timeline

  • 2 hours: Critical PCI DSS violations
  • 4 hours: Payment processing vulnerabilities
  • 8 hours: Financial data exposure
  • 24 hours: Medium severity issues

Severity Classification

Severity Description Examples
Critical PCI data exposure, payment manipulation Card data storage, transaction tampering
High Financial calculation errors, auth bypass Amount manipulation, unauthorized payments
Medium Information disclosure, business logic flaws Payment history leak, validation bypass
Low Minor security improvements Logging issues, configuration improvements

Security Testing

Payment-Specific Testing

Regular security assessments must include:

  • PCI DSS compliance validation
  • Payment flow security testing
  • Tokenization and encryption verification
  • Fraud detection system testing
  • Financial calculation accuracy testing

Automated Security Testing

  • Unit tests for payment validation and processing
  • Integration tests with payment providers
  • Load testing for high-volume payment processing
  • Security tests for PCI DSS compliance

Security Configuration

Required Environment Variables

# Database Security (SQL Server)
ConnectionStrings__DefaultConnection="Server=server;Database=PaymentService;Integrated Security=true;Encrypt=true;TrustServerCertificate=false;Column Encryption Setting=enabled"

# Azure Key Vault
AzureKeyVault__VaultUrl="https://vault.vault.azure.net/"
AzureKeyVault__ClientId="managed-identity-client-id"
AzureKeyVault__TenantId="azure-tenant-id"

# Payment Provider Security
PaymentProviders__Stripe__SecretKeyReference="kv-stripe-secret"
PaymentProviders__Stripe__WebhookSecretReference="kv-stripe-webhook"
PaymentProviders__PayPal__ClientIdReference="kv-paypal-client-id"
PaymentProviders__PayPal__ClientSecretReference="kv-paypal-secret"

# PCI DSS Security
Security__PciComplianceMode=true
Security__EncryptionKeyReference="kv-payment-encryption-key"
Security__TokenizationProvider="Azure"
Security__RequireHttps=true
Security__HstsMaxAge=31536000

# Audit and Compliance
Audit__EnablePaymentAuditLog=true
Audit__RetentionDays=365
Audit__EncryptAuditLogs=true
Compliance__PciDssLogging=true

# Rate Limiting (PCI DSS)
RateLimit__PaymentProcessing=100
RateLimit__PaymentMethodManagement=50
RateLimit__RefundProcessing=20

C# Security Configuration

// PCI DSS compliant startup configuration
public void ConfigureServices(IServiceCollection services)
{
    // Always Encrypted for sensitive columns
    services.AddDbContext<PaymentDbContext>(options =>
    {
        options.UseSqlServer(connectionString, sqlOptions =>
        {
            sqlOptions.EnableRetryOnFailure();
        });
    });

    // Azure Key Vault configuration
    services.AddAzureKeyVault(Configuration);

    // PCI DSS security headers
    services.AddHsts(options =>
    {
        options.Preload = true;
        options.IncludeSubDomains = true;
        options.MaxAge = TimeSpan.FromDays(365);
    });

    // Payment-specific rate limiting
    services.AddRateLimiter(options =>
    {
        options.AddFixedWindowLimiter("PaymentProcessing", opt =>
        {
            opt.PermitLimit = 100;
            opt.Window = TimeSpan.FromMinutes(1);
            opt.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
        });
    });
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // PCI DSS security middleware
    app.UseHttpsRedirection();
    app.UseHsts();
    app.UseSecurityHeaders(); // Custom PCI DSS headers
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseRateLimiter();

    // PCI DSS audit middleware
    app.UsePaymentAuditLogging();
}

PCI DSS Compliance Standards

Compliance Requirements

The Payment Service maintains PCI DSS Level 1 compliance:

  1. Protect stored cardholder data: No storage of actual card data
  2. Encrypt transmission: TLS 1.3 for all communications
  3. Maintain vulnerability management: Regular security updates
  4. Implement strong access control: Multi-factor authentication
  5. Regularly monitor networks: Continuous security monitoring
  6. Maintain information security policy: Documented security procedures

Compliance Testing

  • Quarterly vulnerability scans
  • Annual penetration testing
  • Monthly security reviews
  • Continuous compliance monitoring

Incident Response

Payment Security Incidents

  1. PCI DSS Breach: Immediate isolation and forensic analysis
  2. Payment Fraud: Real-time fraud detection and blocking
  3. Data Exposure: Compliance notification and remediation
  4. Service Compromise: Emergency payment processing halt

Recovery Procedures

  • Payment service isolation and investigation
  • Financial reconciliation and dispute resolution
  • Customer notification for affected payments
  • Regulatory compliance reporting

Third-Party Security

Payment Provider Integration

  • Stripe Security: PCI DSS Level 1 service provider
  • PayPal Security: Industry-standard security compliance
  • Webhook Security: Signature verification for all callbacks
  • API Security: Secure key management and rotation

Contact

For security-related questions or concerns:


Last Updated: September 8, 2025
Next Review: December 8, 2025
Version: 1.0.0

There aren’t any published security advisories