Skip to content

Commit 9987d17

Browse files
Minor edits, heading changes
1 parent 0675cc4 commit 9987d17

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

examples/codex/secure_quality_gitlab.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ To follow along, you’ll need:
2828
* An **OpenAI API key** (`OPENAI_API_KEY`)
2929
* GitLab CI/CD variables configured under **Settings → CI/CD → Variables**
3030

31-
## **Problem Statement \#1 \- Code Quality**
31+
## **Example \#1 \- Using Codex CLI to Produce a Code Quality Report**
3232

3333
### Background
3434

35-
This repository is a deliberately vulnerable Node.js Express demo app based on ([https://gitlab.com/gitlab-org/project-templates/express/-/tree/main](https://gitlab.com/gitlab-org/project-templates/express/-/tree/main)) built to showcase SAST and code quality scanning in GitLab CI/CD. The code includes common pitfalls such as command injection, path traversal, unsafe `eval`, regex DoS, weak cryptography (MD5), and hardcoded secrets. It’s used to validate that Codex-powered analyzers produce GitLab-native reports (Code Quality and SAST) that render directly in merge requests.
35+
This repository is a deliberately vulnerable Node.js Express demo app based on [GitLab's node express template](https://gitlab.com/gitlab-org/project-templates/express/-/tree/main), built to showcase static application security testing (SAST) and code quality scanning in GitLab CI/CD.
36+
37+
The code includes common pitfalls such as command injection, path traversal, unsafe `eval`, regex DoS, weak cryptography (MD5), and hardcoded secrets. It’s used to validate that Codex-powered analyzers produce GitLab-native reports (Code Quality and SAST) that render directly in merge requests.
3638

3739
The CI runs on GitLab SaaS runners with `node:24` images and a few extras (`jq`, `curl`, `ca-certificates`, `ajv-cli`). Jobs are hardened with `set -euo pipefail`, schema validation, and strict JSON markers to keep parsing reliable even if Codex output varies.
3840

3941
This pipeline pattern—prompt, JSON marker extraction, schema validation—can be adapted to other stacks, though prompt wording and schema rules may need tweaks. Since Codex runs in a sandbox, some system commands (like `awk` or `nl`) may be restricted.
4042

4143
Your team wants to ensure that **code quality checks run automatically** before any merge. To surface findings directly in GitLab’s merge request widget, reports must follow the **CodeClimate JSON format**. [Reference: GitLab Docs](https://docs.gitlab.com/ci/testing/code_quality/#import-code-quality-results-from-a-cicd-job)
4244

43-
### CI/CD Job Example
45+
### Code Quality CI/CD Job Example
4446

4547
Here’s a drop-in GitLab CI job using **Codex CLI** to produce a compliant JSON file:
4648
```yaml
@@ -162,24 +164,24 @@ This approach has several benefits:
162164

163165
As teams adopt this workflow, LLM-powered quality checks can complement traditional linting and vulnerability scanning—helping ensure that code shipped to production is both robust and maintainable.
164166

165-
## **Problem Statement \#2 – Security Remediation**
167+
## **Example \#2 – Using Codex CLI for Security Remediation**
166168

167169
### Background
168170

169-
For this problem statement we tested on [OWASP Juice Shop](https://github.com/juice-shop/juice-shop?utm_source=chatgpt.com), a deliberately vulnerable Node.js Express app. It contains common flaws such as injection, unsafe `eval`, weak crypto, and hardcoded secrets—ideal for validating Codex-powered analysis.
171+
For this example, we tested on [OWASP Juice Shop](https://github.com/juice-shop/juice-shop?utm_source=chatgpt.com), a deliberately vulnerable Node.js Express app. It contains common flaws such as injection, unsafe `eval`, weak crypto, and hardcoded secrets—ideal for validating Codex-powered analysis.
170172

171173
Your team wants to ensure that whenever code changes are introduced, the pipeline automatically checks for security vulnerabilities before merge. This is already handled by static analyzers and language-specific scanners, which generate reports in the GitLab SAST JSON schema. However, raw outputs can be rigid, noisy, and often leave reviewers without clear next steps.
172174

173175
By adding Codex CLI into your pipeline, you can turn scanner results generated by [GitLab SAST scanners](https://docs.gitlab.com/user/application_security/sast/) (or other scanner outputs) into **actionable remediation guidance** and even generate **ready-to-apply git patches**:
174176

175-
### Recommendations stage
177+
### Step 1: Generating Recommendations
176178

177179
* Codex reads `gl-sast-report.json`.
178180
* Consolidates duplicate findings.
179181
* Ranks by exploitability (e.g. user input → dangerous sinks).
180182
* Produces a succinct `security_priority.md` with top 5 actions and detailed remediation notes.
181183

182-
#### CI/CD Job Example
184+
#### Security Recommendations CI/CD Job Example
183185

184186
**Requirement**: This job expects that upstream SAST jobs already generated a `gl-sast-report.json`. Codex reads it and produces `security_priority.md` for reviewers.
185187

@@ -300,9 +302,9 @@ codex_recommendations:
300302
- security_priority.md
301303
expire_in: 14 days
302304
```
303-
The output results look like this
305+
Here's an example of the output we receive:
304306
305-
# Consolidated SAST Findings
307+
# Example Output: Consolidated SAST Findings
306308
307309
Parsed `gl-sast-report.json` and merged overlapping issues.
308310
**Total raw findings:** 5 → **Consolidated into:** 4 representative entries
@@ -360,15 +362,15 @@ Parsed `gl-sast-report.json` and merged overlapping issues.
360362
- Owners/Teams: Backend/API (routes)
361363
- References: OWASP SSRF Prevention; OWASP Top 10 A10:2021
362364
---
363-
### Remediation Stage Workflow
365+
### Step 2: Remediating Security Issues Based on Recommendations
364366
- Codex consumes both the SAST JSON and the repo tree.
365367
- For each High/Critical issue:
366368
- Builds a structured prompt → outputs a unified `git diff`.
367369
- Diff is validated (`git apply --check`) before being stored as `.patch`.
368370

369-
### CI/CD Job Example
371+
#### Remediation CI/CD Job Example
370372

371-
**Requirement**: This job depends on the previous stage output of the `security_priority.md` file to use as input to generate the patch file for creating an MR
373+
**Requirement**: This job depends on the previous stage output of the `security_priority.md` file to use as input to generate the patch file for creating an MR:
372374
```yaml
373375
stages:
374376
- remediation
@@ -519,7 +521,7 @@ codex_resolution:
519521
expire_in: 14 days
520522
```
521523
522-
Example generated patch:
524+
Running the CI/CD job with Codex CLI, we receive a Git patch that fixes the issues originally found by our security scanner:
523525
524526
```patch
525527
<unified diff here>
@@ -576,12 +578,13 @@ export function profileImageUrlUpload () {
576578
return
577579
```
578580

579-
## **Why Does It Matters?**
581+
## Key Benefits
582+
Using Codex CLI in GitLab CI/CD allows you to augment existing review processes so that your team can ship faster.
580583

581-
* **Keeps existing scanners as the source of truth**: No changes to how vulnerabilities are detected.
584+
* **Complementary**: Codex doesn’t replace scanners — it interprets their findings and accelerates fixes.
582585
* **Actionable**: Reviewers see not just vulnerabilities, but prioritized steps to fix them.
583586
* **Automated**: Patches are created directly in CI, ready for `git apply` or a remediation branch.
584-
* **Complementary**: Codex doesn’t replace scanners — it interprets their findings and accelerates fixes.
587+
585588
---
586589

587590
## **Wrapping Up**

0 commit comments

Comments
 (0)