osec.one case analysis cover: GitLab 2024: CVE-2024-0402 arbitrary file write, account takeover and CI token exposure

On 25 January 2024, GitLab published an urgent critical security release addressing CVE-2024-0402, a flaw carrying a near-maximum CVSS score of 9.9. Discovered internally by GitLab security researcher joernchen, the vulnerability allowed an authenticated user to perform arbitrary file writes across the underlying operating system during the creation of a developer workspace.

Modern DevOps organizations rely on centralized code repositories not just for source control, but as the execution engine for automated CI/CD builds, release signing, and cloud deployment credentials. When an attacker gains arbitrary file write on a GitLab server, the blast radius does not stop at a damaged file—it immediately expands into root remote code execution (RCE), complete repository exposure, and the theft of CI/CD runner secrets.

Six steps from a malicious devfile registry to arbitrary file write and RCE
The attack chain of CVE-2024-0402: from a custom Devfile parent registry to directory traversal and host-level shell access.

Vulnerability overview by the numbers

MetricDetailsImpact & context
CVE IdentifierCVE-2024-0402NVD Common Vulnerabilities and Exposures record
CVSS v3.1 Score9.9 (Critical)CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
Vulnerability ClassPath Traversal (CWE-22)Improper limitation of pathname to restricted directory
Affected ComponentGitLab Workspaces / Devfile ParserGo helper binary invoked by GitLab Rails backend
Affected Versions16.0 to 16.5.7, 16.6 to 16.6.5, 16.7 to 16.7.3, 16.8.0All self-managed GitLab CE/EE instances running Workspaces
Fixed Release Versions16.5.8, 16.6.6, 16.7.4, 16.8.1Backported security patches released 25 January 2024
Attack PrerequisiteAuthenticated account (Low privilege)Any user with permission to create a workspace in a project
Exploitation OutcomeArbitrary Host File Write → RCEWrite access as `git` user; shell execution; database token access

To understand how a file write emerged from a developer workspace, one must examine the architecture of cloud-based development environments.

The feature: cloud workspaces and the Devfile standard

Starting in GitLab 16.0 (May 2023), GitLab introduced Remote Development Workspaces. Similar to GitHub Codespaces or Gitpod, GitLab Workspaces let engineers launch on-demand, containerized development environments directly from browser IDEs. Workspaces are configured through an open standard called a Devfile (typically .devfile.yaml in the root of the repository).

A Devfile defines the developer's container tools, environment variables, ports, and parent templates. A typical Devfile references a parent stack configuration:
```yaml
schemaVersion: 2.2.0
metadata:
name: nodejs-app
parent:
id: nodejs
registryUrl: https://registry.devfile.io
```
When a developer creates a workspace, GitLab parses the .devfile.yaml using an in-house Ruby gem (devfile-gem) that communicates with an external Go-based helper binary (devfile). The parser fetches the parent stack definition from the specified registryUrl, extracts the packaged configuration archive, merges the project configuration with the parent template, and sends the final container manifest to the Kubernetes GitLab Agent (kas).

The root cause: path traversal inside archive extraction

The vulnerability lies in how the Go helper binary processed stack archives fetched from remote Devfile registries. When a parent stack is requested, the registry responds with a compressed tarball or zip archive containing the component specifications.

Security research by firm Doyensec (!exploitable Episode Three: Devfile Adventures) and GitLab's internal notes dissected the extraction mechanics. The unpack routine extracted files into a temporary directory on the GitLab host. However, the extractor failed to perform strict sanitization on the file names contained within the archive header entries:

StepExpected behaviorVulnerable execution (CVE-2024-0402)
1. Registry resolutionQuery trusted devfile registry (`registry.devfile.io`).Attacker configures an arbitrary, attacker-controlled registry URL in `.devfile.yaml`.
2. Template archive downloadDownload official stack archive (e.g., standard Node.js dev environment).Attacker's rogue registry serves a crafted tarball containing entries with `../../` relative paths.
3. Archive extractionExtract files strictly within sandbox `/tmp/devfile-workdir-xxxx/`.Extraction loop failed to verify target paths stayed within sandbox boundaries.
4. Path resolutionTarget path resolved as `SANDBOX_DIR + filename`.Canonical path escaped the sandbox: e.g., `/tmp/workdir/../../../../var/opt/gitlab/.ssh/authorized_keys`.
5. File write executionWrite configuration files into temporary workspace directory.Arbitrary file written directly onto the host filesystem under the privileges of the GitLab backend user (`git`).

Because the extraction loop did not enforce destination path confinement (filepath.Clean and prefix boundary validation), archive entries containing path traversal sequences escaped the temporary scratch directory and overwrote files across the host.

From arbitrary file write to full instance takeover

In a standard web application, an arbitrary file write often allows denial-of-service or configuration corruption. On a GitLab Omnibus or self-managed deployment, an arbitrary file write running as the system git user is an immediate bridge to Remote Code Execution (RCE):

• SSH Key Injection (authorized_keys): On Linux GitLab servers, the git user account manages Git-over-SSH repositories. Its SSH authorized keys file sits at /var/opt/gitlab/.ssh/authorized_keys. By crafting a tarball entry targeting ../../../../var/opt/gitlab/.ssh/authorized_keys, an attacker could append their personal SSH public key. Once written, the attacker could connect via SSH (ssh git@gitlab.target.com) and obtain an interactive shell session.
• Rails Session Secret Forgery: GitLab stores Rails encryption secrets in /opt/gitlab/embedded/service/gitlab-rails/config/secrets.yml. Overwriting or modifying this file allows an attacker to sign their own arbitrary Rails cookies, instantly impersonating instance administrators.
• Webhooks and Executable Script Overwrites: Writing executable hooks into Git server-side custom hooks (custom_hooks/post-receive) executes attacker commands automatically on subsequent git pushes.

The CI/CD blast radius: what attackers steal after host access

Gaining shell access as git on a self-managed GitLab instance exposes the entire software delivery pipeline. The table below details the credentials and assets exposed:

Credential / AssetLocation / StorageAttacker capability
Repository Source Code`/var/opt/gitlab/git-data/repositories`Complete read and write access to all private projects, proprietary code, and commit history.
CI Runner TokensGitLab Database (`ci_runners` table)Register rogue CI runners or hijack existing runners to intercept build jobs across the company.
CI/CD Job Tokens (`CI_JOB_TOKEN`)Dynamic environment / runner memoryAccess cross-project dependencies, package registries, and container images.
Production Secrets & Env VarsGitLab Database (`ci_variables` encrypted with `db_key_base`)Once `secrets.yml` is compromised, all CI/CD variables (AWS keys, Kubernetes kubeconfigs, production DB passwords) are decryptable.
Group & Project Deploy TokensDatabase tablesRead and push malicious packages directly to GitLab Package Registry and Container Registry.

An attacker with access to the GitLab server can silently inject malicious code into CI build scripts, publish trojaned container images, or backdoor production application binaries before deployment.

The January 2024 attack wave: chaining vulnerabilities

Although CVE-2024-0402 required an authenticated user account to create a workspace, the attack prerequisite was trivialized by events occurring in the same month:

1. Open User Registration: Thousands of self-managed GitLab servers operate with public user registration enabled by default. Any unauthenticated attacker could register an unprivileged account, create a private project, configure a .devfile.yaml, and trigger the workspace creation exploit.
2. CVE-2023-7028 (Jan 11, 2024): Exactly two weeks prior, GitLab disclosed CVE-2023-7028 (CVSS 10.0), a catastrophic unauthenticated password reset vulnerability where password reset emails could be sent to an attacker-controlled secondary email address. Attackers exploited CVE-2023-7028 to hijack existing user accounts on unpatched instances, providing immediate authenticated access to exploit CVE-2024-0402.

How this compares to other developer infrastructure attacks

Developer tooling and CI/CD platforms have become primary targets for state-sponsored and cybercrime operators. Comparing CVE-2024-0402 with notable developer supply-chain incidents illustrates the threat landscape:

IncidentAttack vectorInitial compromise pointUltimate blast radius
GitLab CVE-2024-0402 (2024)Path traversal archive extraction (CWE-22)Devfile workspace parent stack registryArbitrary host file write, RCE, database & CI runner secrets compromise
Nx s1ngularity (2025)GitHub Actions workflow command injectionPull request title and commit payload injectionNPM publish tokens stolen; malicious package versions released to registry
Ultralytics (2024)CI build workflow environment poisoningCompromised workflow runner permissionsPoisoned PyPI releases with crypto-mining malware built by official workflow
CircleCI (2023)Malware infostealer on engineer laptopStolen SSO session cookieAll customer build secrets, cloud API keys, and deployment credentials compromised

Architectural defenses: isolating workspaces and CI/CD pipelines

The lesson from CVE-2024-0402 is clear: complex features like developer workspaces must never be parsed or executed with write access to the host server's root filesystem. Organizations running self-managed or enterprise developer platforms should adopt five structural safeguards:

1. Isolate workspace runtimes to ephemeral Kubernetes pods: Never run workspace provisioning or parsing helpers on the core application server. Workspace provisioning should occur inside restricted Kubernetes namespaces using non-root security contexts (runAsNonRoot: true), read-only root filesystems (readOnlyRootFilesystem: true), and drop: ["ALL"] capabilities.
2. Restrict and allowlist Devfile registries: Block the fetching of parent Devfile stacks from arbitrary public internet URLs. Enforce an internal registry allowlist (e.g. only verified internal mirrors or approved organization registries).
3. Disable public registration and enforce strict auth: Disable open signup on self-managed code platforms. Protect all user accounts with phishing-resistant MFA (passkeys or hardware tokens) to prevent attackers from using compromised credentials to reach workspace features.
4. Audit and pin all CI workflow dependencies: Build pipelines should not pull unversioned actions or remote scripts. Tools like the free osec Action pin lookup allow teams to pin CI actions to immutable commit SHAs in seconds, while the osec Workflow risk check identifies unpinned actions and permission over-scoping.
5. Use short-lived OIDC tokens instead of static cloud secrets: Eliminate long-lived AWS, GCP, or Kubernetes tokens stored in CI/CD environment variables. Transition all automated deployments to OpenID Connect (OIDC) identity federation, ensuring build runners receive temporary, narrowly scoped tokens that expire in minutes.

To verify that your web perimeters, SSL setups, and edge endpoints do not leave open attack surfaces, check your domain with the free osec Site Protection Scan.

Protect your authentication endpoints with osec Auth: passwordless sign-in with email codes, Google, and Apple, eliminating password theft and credential-stuffing risks with zero DNS configuration.

Explore osec.one

Sources

• GitLab Critical Security Release, GitLab Security Advisory 16.8.1, 16.7.4, 16.6.6, 16.5.8 (25 Jan 2024): https://about.gitlab.com/releases/2024/01/25/critical-security-release-gitlab-16-8-1-released/
• National Vulnerability Database (NVD), CVE-2024-0402 Detail (CVSS 9.9): https://nvd.nist.gov/vuln/detail/CVE-2024-0402
• GitLab Security Tech Notes, Devfile file write vulnerability in GitLab: https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/
• Doyensec Research, !exploitable Episode Three - Devfile Adventures: https://doyensec.com/blog/2024/05/28/devfile-file-write/
• Doyensec GitHub Repository, malicious-devfile-registry proof of concept: https://github.com/doyensec/malicious-devfile-registry
• Devfile.io Open Standard, Devfile v2.2.0 Specification: https://devfile.io/docs/2.2.0/devfile-schema
• osec.one case study, Nx s1ngularity 2025: a workflow injection that published malicious npm packages: https://osec.one/articles/nx-s1ngularity-2025-workflow-injection-npm-ai-tools-secrets
• osec.one case study, CircleCI 2023: a session cookie from an engineer's laptop, and every customer told to rotate every secret: https://osec.one/articles/circleci-2023-engineer-session-cookie-customer-secrets-rotation
• osec.one case study, Ultralytics 2024: a poisoned PyPI release built by the project's own GitHub workflow: https://osec.one/articles/ultralytics-2024-poisoned-pypi-release-built-by-github-workflow