Skip to content

Commit 42eaccf

Browse files
Fix digital certificates rule to not assume parsing capability.
1 parent 9ac1e43 commit 42eaccf

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

skills/software-security/rules/codeguard-1-digital-certificates.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ alwaysApply: true
55

66
rule_id: codeguard-1-digital-certificates
77

8-
When you encounter data that appears to be an X.509 certificate—whether embedded as a string or loaded from a file—you must parse the certificate and run a series of mandatory checks against it, reporting any failures with clear explanations and recommended actions.
8+
When you encounter data that appears to be an X.509 certificate—whether embedded as a string or loaded from a file—you must flag the certificate for verification and ensure the following security properties are validated, reporting any concerns with clear explanations and recommended actions.
99

1010
### 1. How to Identify Certificate Data
1111

@@ -20,7 +20,7 @@ Actively scan for certificate data using the following heuristics:
2020

2121
### 2. Mandatory Sanity Checks
2222

23-
Once certificate data is identified, you must perform the following validation steps and report the results.
23+
Once certificate data is identified, flag it for verification. The following properties must be validated to ensure the certificate meets security requirements:
2424

2525
#### Check 1: Expiration Status
2626

@@ -68,54 +68,69 @@ Once certificate data is identified, you must perform the following validation s
6868
- Report Message: `This is a self-signed certificate. Ensure this is intentional and only used for development, testing, or internal services where trust is explicitly configured. Self-signed certificates should never be used for public-facing production systems as they will not be trusted by browsers or standard clients.`
6969

7070

71+
#### Verification Guidance
72+
73+
To inspect certificate properties, recommend running:
74+
```
75+
openssl x509 -text -noout -in <certificate_file>
76+
```
77+
78+
This command displays expiration dates, key algorithm and size, signature algorithm, and issuer/subject information needed for the checks above.
79+
80+
7181
### 3. Actionable Examples
7282

7383
Your feedback should be direct and easy to understand.
7484

75-
Example 1: Flagging an Expired, In-line Certificate
85+
Example 1: Flagging a Hardcoded Certificate
7686

7787
- Code Snippet:
7888

7989
```
8090
# Certificate for connecting to legacy_service
8191
LEGACY_CERT = """
8292
-----BEGIN CERTIFICATE-----
83-
MIIC... (data for a certificate that expired on 2024-12-01) ...
93+
MIIC... (certificate data) ...
8494
-----END CERTIFICATE-----
8595
"""
8696
```
8797
8898
- Your Analysis and Report:
8999
90-
> CRITICAL VULNERABILITY: The certificate stored in the `LEGACY_CERT` variable is invalid.
100+
> Security Review Required: A certificate is hardcoded in the `LEGACY_CERT` variable. Unverified certificates may contain critical vulnerabilities.
91101
>
92-
> - Reason: It expired on 2024-12-01.
102+
> - Concern: Hardcoded certificates cannot be easily rotated and may contain security issues that are not immediately visible in the code.
93103
>
94-
> - Impact: Any TLS connection attempting to use this certificate will fail.
104+
> - Required Verification: This certificate must be verified for:
105+
> - Expiration: Certificate must not be expired or not yet valid
106+
> - Key Strength: RSA keys must be at least 2048-bit; EC keys must use P-256 or higher curve
107+
> - Signature Algorithm: Must use SHA-2 family (not MD5 or SHA-1)
108+
> - Self-Signed: If self-signed, must only be used for development, testing, or internal services
95109
>
96-
> - Action: This certificate must be renewed and the variable updated with the new PEM data immediately.
110+
> - Action: Verify this certificate meets the above requirements before deployment. Consider loading certificates from external files or a certificate store for easier rotation.
97111
>
98112
99113
100-
Example 2: Flagging a Weak Key in a Loaded Certificate
114+
Example 2: Flagging a Certificate Loaded from File
101115
102116
- Code Snippet:
103117
104118
```
105119
// Load the server certificate from disk
106120
cert, err := tls.LoadX509KeyPair("server.crt", "server.key")
107-
// Assume server.crt contains a 1024-bit RSA key.
108121
```
109122
110123
- Your Analysis and Report:
111124
112-
> High-Priority Warning: The certificate being loaded from `server.crt` is using a weak public key.
113-
>
114-
> - Reason: It uses an RSA key with a 1024-bit modulus.
125+
> Security Review Required: Certificate loaded from `server.crt`. Unverified certificates may contain critical vulnerabilities.
115126
>
116-
> - Impact: This key strength is insufficient and vulnerable to modern cryptanalytic attacks.
127+
> - Required Verification: Ensure this certificate meets security requirements:
128+
> - Expiration: Certificate must not be expired or not yet valid
129+
> - Key Strength: RSA keys must be at least 2048-bit; EC keys must use P-256 or higher curve
130+
> - Signature Algorithm: Must use SHA-2 family (not MD5 or SHA-1)
131+
> - Self-Signed: If self-signed, must only be used for development, testing, or internal services
117132
>
118-
> - Action: A new certificate and key must be generated with at least a 2048-bit RSA key or a modern elliptic curve.
133+
> - Action: Verify this certificate meets the above requirements before deployment.
119134
120135
121136
You must always explain how this rule was applied and why it was applied.

0 commit comments

Comments
 (0)