You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## **Example \#1 \-Using Codex CLI to Produce a Code Quality Report**
32
32
33
33
### Background
34
34
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.
36
38
37
39
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.
38
40
39
41
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.
40
42
41
43
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)
42
44
43
-
### CI/CD Job Example
45
+
### Code Quality CI/CD Job Example
44
46
45
47
Here’s a drop-in GitLab CI job using **Codex CLI** to produce a compliant JSON file:
46
48
```yaml
@@ -162,24 +164,24 @@ This approach has several benefits:
162
164
163
165
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.
## **Example \#2 – Using Codex CLI for Security Remediation**
166
168
167
169
### Background
168
170
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.
170
172
171
173
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.
172
174
173
175
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**:
174
176
175
-
### Recommendations stage
177
+
### Step 1: Generating Recommendations
176
178
177
179
* Codex reads `gl-sast-report.json`.
178
180
* Consolidates duplicate findings.
179
181
* Ranks by exploitability (e.g. user input → dangerous sinks).
180
182
* Produces a succinct `security_priority.md` with top 5 actions and detailed remediation notes.
181
183
182
-
#### CI/CD Job Example
184
+
#### Security Recommendations CI/CD Job Example
183
185
184
186
**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.
185
187
@@ -300,9 +302,9 @@ codex_recommendations:
300
302
- security_priority.md
301
303
expire_in: 14 days
302
304
```
303
-
The output results look like this
305
+
Here's an example of the output we receive:
304
306
305
-
# Consolidated SAST Findings
307
+
# Example Output: Consolidated SAST Findings
306
308
307
309
Parsed `gl-sast-report.json` and merged overlapping issues.
308
310
**Total raw findings:** 5 → **Consolidated into:** 4 representative entries
@@ -360,15 +362,15 @@ Parsed `gl-sast-report.json` and merged overlapping issues.
360
362
- Owners/Teams: Backend/API (routes)
361
363
- References: OWASP SSRF Prevention; OWASP Top 10 A10:2021
362
364
---
363
-
### Remediation Stage Workflow
365
+
### Step 2: Remediating Security Issues Based on Recommendations
364
366
- Codex consumes both the SAST JSON and the repo tree.
365
367
- For each High/Critical issue:
366
368
- Builds a structured prompt → outputs a unified `git diff`.
367
369
- Diff is validated (`git apply --check`) before being stored as `.patch`.
368
370
369
-
### CI/CD Job Example
371
+
#### Remediation CI/CD Job Example
370
372
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:
372
374
```yaml
373
375
stages:
374
376
- remediation
@@ -519,7 +521,7 @@ codex_resolution:
519
521
expire_in: 14 days
520
522
```
521
523
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:
523
525
524
526
```patch
525
527
<unified diff here>
@@ -576,12 +578,13 @@ export function profileImageUrlUpload () {
576
578
return
577
579
```
578
580
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.
580
583
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.
582
585
***Actionable**: Reviewers see not just vulnerabilities, but prioritized steps to fix them.
583
586
***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.
0 commit comments