# Security Patterns Analysis

> [← Back to README](../README.md) | [Dependency Analysis](./dependency-analysis.md)

## Authentication Implementation (COSGN00C)

**Source:** `app/cbl/COSGN00C.cbl`

### Mechanism
- User credentials stored in USRSEC VSAM KSDS file
- Key: SEC-USR-ID (8 characters), Password: SEC-USR-PWD (8 characters)
- Plaintext password comparison: `IF SEC-USR-PWD = WS-USER-PWD` (line 223)
- No password hashing, encryption, or salting

### Security Concerns — 🔴 HIGH
1. **Plaintext passwords** stored in VSAM file (SEC-USR-PWD field)
2. **No password complexity** enforcement
3. **No account lockout** after failed attempts
4. **No session timeout** mechanism (beyond CICS region defaults)
5. **No audit logging** of authentication attempts

## Authorization Model

### Role-Based Access
- Two roles: Regular User (SEC-USR-TYPE ≠ 'A') and Admin (SEC-USR-TYPE = 'A')
- Role check performed in COSGN00C, stored in COMMAREA
- Menu programs (COMEN01C, COADM01C) filter options based on user type

### Security Concerns — 🟡 MEDIUM
1. **COMMAREA-based authorization** — user type flag could theoretically be manipulated
2. **No function-level security** — once authenticated, users can access any function in their menu
3. **No data-level security** — users can view/modify any account, not just their own

## Hardcoded Credentials

**From README.md:**
```
Admin access: userid ADMIN001, password PASSWORD
User access:  userid USER0001, password PASSWORD
```
- Default credentials documented in repository
- Same password for both admin and regular users
- No forced password change on first login

### Security Concern — 🔴 HIGH
Default credentials are publicly documented and use trivial password.

## RACF Integration Points

- RACF mentioned in README as security technology
- CSD definitions show `RESSEC(NO) CMDSEC(NO)` for all transactions
- This means **resource security and command security are DISABLED** at the transaction level

### Security Concern — 🔴 HIGH
RACF security checking is explicitly disabled in the CSD definitions.

## Data Validation Patterns

### Input Validation (BMS Programs)
- Field-level validation in update programs (COACTUPC, COCRDUPC, COTRTUPC)
- Validation flags (FLG-xxx-OK, FLG-xxx-BLANK, FLG-xxx-NOT-OK)
- Date validation via CSUTLDWY/CSUTLDPY copybooks
- State/ZIP lookup validation via CSLKPCDY (1,318 lines of lookup tables)

### Security Concern — 🟡 MEDIUM
- No explicit input sanitization beyond type/format checking
- BMS provides basic field-level attribute protection (numeric, alphanumeric)
- Potential for data injection through unvalidated fields in some programs

## DB2 SQL Patterns (Optional Modules)

### SQL Operations in COTRTLIC, COTRTUPC, COBTUPDT
- Uses embedded SQL with host variables (standard COBOL SQL pattern)
- DB2 precompiler handles SQL injection prevention for static SQL
- No dynamic SQL detected — **low SQL injection risk**

## Sensitive Data Handling

| Data Element | Copybook | Protection |
|:------------|:---------|:-----------|
| SEC-USR-PWD (password) | CSUSR01Y | ❌ Plaintext |
| CUST-SSN (SSN) | CVCUS01Y | ❌ No encryption |
| CARD-NUM (card number) | CVACT02Y | ❌ No masking in storage |
| CARD-CVV-CD (CVV) | CVACT02Y | ❌ No encryption |
| CUST-GOVT-ISSUED-ID | CVCUS01Y | ❌ No encryption |

### Security Concern — 🔴 HIGH
Sensitive PII and payment card data stored without encryption or masking.

## Summary of Security Findings

| Finding | Severity | Location |
|:--------|:---------|:---------|
| Plaintext password storage | 🔴 Critical | CSUSR01Y, COSGN00C |
| Default credentials in docs | 🔴 Critical | README.md |
| RACF security disabled in CSD | 🔴 Critical | CARDDEMO.CSD |
| No PCI DSS compliance for card data | 🔴 Critical | CVACT02Y |
| Sensitive PII unencrypted | 🔴 High | CVCUS01Y |
| No account lockout | 🟡 Medium | COSGN00C |
| COMMAREA-based auth | 🟡 Medium | COCOM01Y |
| No audit trail | 🟡 Medium | All programs |
| Limited input validation | 🟡 Medium | BMS programs |

---

*See also: [Technical Debt - Security](../technical-debt/security-vulnerabilities.md) | [Error Handling](../behavior/error-handling.md)*
