Devfile file write vulnerability in Gitlab – walkthrough finding CVE-2024-0402

https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/

This post is a extensive walkthrough of the process of identifying and exploiting CVE-2024-0402.

The vulnerability in GitLab was fixed on January 25th 2024 with a Critical Security Release.

Sometimes exploits for vulnerabilities are like onions: they have layers. This particular exploit had several layers and two underlying vulnerabilities which were used in combination to achieve an arbitrary file write on a GitLab instance. This file write then can be further abused to run arbitrary commands on a GitLab instance. This post will cover the general approaches to identify such issues and the technical details the exploit relies upon. However we'll spare the full end-to-end exploit as we deem the underlying techniques and approaches much more relevant in general than sharing an exploit for a patched vulnerability.

Starting point: dependencies

The adventure started by looking at the dependencies of the GitLab main project.

While looking for some low-hanging fruit in the project dependencies I noticed the devfile Gem making calls to an external helper binary by using Open3.capture3. Calling external binaries is a typical red flag for me, there are many things which might go sideways. Command or Argument injections for example, or other surprises from lesser known features of the called binary. Not to speak of actual vulnerabilities in the binary or its dependencies.

Notably the devfile Gem is written in-house at GitLab. A quick review of the repository revealed some Go based code from which the devfile binary called by the Ruby Gem was being created. I didn't know much about Devfiles at this point. I only had the vague concept in the back of my head that those were YAML files used to describe the environments for GitLab's Workspaces feature.

Workspaces are isolated web-based development environments which are deployed by the GitLab application into Kubernetes clusters. Zooming out a bit we have:

  • Devfiles: YAML files which are used to describe Workspaces in Kubernetes environments
  • A Ruby library which parses those devfiles by calling a Go based helper binary

A quick check of the Ruby code calling the Go binary showed there were no surprises or low hanging fruits. The binary is being called directly with no shell being involved, simple command injections were not possible. Also the Go binary had no opportunity for Argument injections.

Digging deeper

Sometimes it's great to just start messing around with a software to get a feeling for potential vulnerabilities. The design of the devfile Gem made this easy. I could just use the included Go based binary and feed it some YAML. Digging into the documentation and looking for some sample files to use I came across the parent feature which allows another devfile to be specified. That file is then used as a base for your current devfile. I used the example from the documentation with the devfile binary in the Gem like so:

joern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ ls
devfile
joern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ ./devfile flatten 'schemaVersion: 2.2.0
metadata:
  name: my-project-dev
parent:
  uri: https://raw.githubusercontent.com/devfile/registry/main/stacks/nodejs/devfile.yaml'
failed to populateAndParseDevfile: error getting devfile info from url: failed to retrieve https://raw.githubusercontent.com/devfile/registry/main/stacks/nodejs/devfile.yaml, 404: Not Foundjoern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ 

I was quite surprised when I did a ls in the directory after that command:

joern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ ls
2.1.1  2.2.0  devfile  OWNERS  stack.yaml

A directory from the devfile/registry repository has been copied into the working directory where I ran the ./devfile command. This was the moment I figured I might be on to something worth spending some more time on.

One step back and three steps forward

The I'll copy some stuff from the Internet into your working directory when you parse a devfile thing was very promising. I was hoping to use this vector to gain an arbitrary file write from it. Should be easy enough, all I needed to do was to figure out the code path from within GitLab to trigger the dependency to flatten a devfile I crafted. That, and yes maybe a traversal out of the working directory, maybe not. That would depend on my current unknowns where on a GitLab instance this working directory would be and what I would control in terms of written files. But overall, this issue looked like a juicy starting place.

So I took a deeper dive into the main Ruby on Rails codebase of GitLab, just to find out that there's a validation to prevent the usage of that parent feature in a devfile. This was really inconvenient, I almost saw that awesome file write vanish in that line of code:

return err(_("Inheriting from 'parent' is not yet supported")) if devfile['parent']

But it wasn't really that bad, this roadblock was something for which I was prepared. In May 2023 I was "messing" with YAML files. This was inspired by a blog post from Jake Miller about parser differentials in JSON parsers, as JSON and YAML are somewhat similar in their use cases, but YAML is a bit more complex I thought it might be worthwhile looking at YAML from a parser differential perspective. Back then I was able to craft a YAML file which would parse differently in Ruby and Python. However it would parse the same in Ruby and in Go, so I "just" needed to find a similar parser differential in Go and in Ruby. Let's first look at the initial YAML file targeting Ruby/Go vs. Python:

joern@host2:~/projects/devfile$ cat 1.yaml 
test: python
!!binary dGVzdA==: ruby & go
joern@host2:~/projects/devfile$ python -c 'import yaml;x = yaml.safe_load(open("1.yaml"));print(x["test"])'
python
joern@host2:~/projects/devfile$ ruby -ryaml -e 'x = YAML.safe_load(File.read("1.yaml"));puts x["test"]'
ruby & go
joern@host2:~/projects/devfile$ cat g.go 
package main
import (
        "fmt"
        "log"
        "os"
        "gopkg.in/yaml.v3"
)
func main() {
    data, _ := os.ReadFile(os.Args[1])
        unmarshalled := &yaml.Node{}
        err := yaml.Unmarshal([]byte(data), unmarshalled)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        var expanded interface{}
        err = unmarshalled.Content[0].Decode(&expanded)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        d, err := yaml.Marshal(expanded)
        if err != nil {
                log.Fatalf("error: %v", err)
        }
        fmt.Printf("%s\n", string(d))
}
joern@host2:~/projects/devfile$ go run g.go 1.yaml
test: ruby & go

The very simple "secret sauce" here is using the !!binary notation to introduce a Base64 encoded key:

test: python
!!binary dGVzdA==: ruby & go

The Base64 (!!binary) string dGVzdA== becomes test when being decoded. In Ruby and in Go this will overwrite the previously defined test: python value. But in Python the following will happen:

python -c 'import yaml;y = yaml.safe_load(open("1.yaml"));print(y)'        
{'test': 'python', b'test': 'ruby & go'}

The !!binary notation will create a Binary Sequence (b'test') in Python which is different from the string test. So we'll have two keys, test and b'test' here, instead of one overwriting the other like it happens in Ruby and Go.

This behavior was the base I had ready, would GitLab have been a Python code base with the same Go parser backend this would've been ready to use right away to bypass the parent key filtering. Unfortunately this isn't the case so I had to find a different way to bypass the key filter.

I spent a bit of time reading about Tags in YAML and noticed the line Local tags start with “!”. Well OK then I thought, let's just try and see what happens when I use !binary instead of !!binary:

joern@host2:~/projects/devfile$ cat 2.yaml
test: non-binary 
!binary dGVzdA==: binary
joern@host2:~/projects/devfile$ ruby -ryaml -e 'x = YAML.safe_load(File.read("2.yaml"));puts x'
{"test"=>"binary"}
joern@host2:~/projects/devfile$ go run g.go 2.yaml
dGVzdA==: binary
test: non-binary
joern@host2:~/projects/devfile$ 

Yes, it really was that "easy". Having this !binary behavior difference in Ruby and Go we can construct a YAML file like:

whatever: is here
!binary parent: hehehe injected

Now when we look at it through the eyes of Ruby it will appear as:

joern@host2:~/projects/devfile$ ruby -ryaml -e 'x = YAML.safe_load(File.read("what.yaml"));puts x'
{"whatever"=>"is here", "\xA5\xAA\xDE\x9E"=>"hehehe injected"}

The !binary value has been decoded to a binary key "\xA5\xAA\xDE\x9E" and now, drumroll for the Go parser:

joern@host2:~/projects/devfile$ go run g.go what.yaml 
parent: hehehe injected
whatever: is here

The !binary tag has just been silently dropped and the resulting YAML key is called parent. These two behaviors combined are exactly what we need to bypass the Ruby validation for the parent key in the Devfile YAML.

Writing files where they don't belong

Now that we're able to sneak the parent key past Ruby and into the Go code it is time to dig deeper into the devfile library and the odd file writing behavior to the working directory I noticed earlier.

First of all, I wanted to know where that working directory was when the devfile binary from the Gem was called on a GitLab instance. I was hoping that it would be somewhat useful directory from an exploitation perspective.

To find this out I looked at the documentation howto set up GitLab Workspaces. There's quite a lot of requirements here to set up those Workspaces properly, a Kubernetes Cluster and a GitLab Agent for it, as well as certain configuration projects on the GitLab instance to set up and tie everything together. The TL;DR of my test setup was to run everything locally. GitLab was run using Docker and the Kubernetes side was set up with minikube.

With those two pieces in place we can connect the minkube cluster with the GitLab Agent to a project in a group on the GitLab instance. In another within the same group we can then create a .devfile.yaml with the following content:

schemaVersion: 2.2.0
!binary parent: 
    uri: https://raw.githubusercontent.com/devfile/registry/main/stacks/nodejs/devfile.yaml'

To trigger the Devfile parsing we now just need to create a workspace for that project:

new workspace

After this step I logged into the GitLab Docker container and searched for the file stack.yaml which was present when I parsed the same Devfile earlier when I initially observed the file writing behavior.

root@localhost:/# find . -name stack.yaml 2> /dev/null 
./var/opt/gitlab/gitlab-rails/working/stack.yaml
root@localhost:/# cd /var/opt/gitlab/gitlab-rails/working/
root@localhost:/var/opt/gitlab/gitlab-rails/working# ls -lart
total 46
drwxr-xr-x 9 git root  12 Apr 11 12:59 ..
-rw-r--r-- 1 git git  283 Apr 12 13:09 stack.yaml
-rw-r--r-- 1 git git   73 Apr 12 13:09 OWNERS
drwxr-xr-x 2 git git    2 Apr 12 13:09 2.2.0
drwxr-xr-x 2 git git    2 Apr 12 13:09 2.1.1
drwx------ 4 git root   6 Apr 12 13:09 .

This result was not very promising, the directory was empty besides the files written via the Devfile parser. While there might be some race conditions with other parts of GitLab where we could write into temporary directories I decided to not go down this route and instead dig deeper into the Devfile library.

The main logic which parses the parent key in the Devfile was quickly identified. It starts in parseParentAndPlugin(). The name of the function already indicates another similar feature comparable to parent, namely the plugin. As both features, parent and plugin had pretty much the same underlying logic in a switch statement for plugin and for parent:

switch {
case parent.Uri != "":
    parentDevfileObj, err = parseFromURI(parent.ImportReference, d.Ctx, resolveCtx, tool)
case parent.Id != "":
    parentDevfileObj, err = parseFromRegistry(parent.ImportReference, resolveCtx, tool)
case parent.Kubernetes != nil:
    parentDevfileObj, err = parseFromKubeCRD(parent.ImportReference, resolveCtx, tool)
default:
    return fmt.Errorf("devfile parent does not define any resources")
}

I digged deeper into the parseFrom* methods. At first I looked into parseFromURI, a URI to download a Devfile from I thought, should be easy enough. Surprisingly it was not that easy. The parseFromURI function had quite some logic involved about local and remote URLs. What caught my attention was:

if tool.downloadGitResources {
    destDir := path.Dir(curDevfileCtx.GetAbsPath())
    err = tool.devfileUtilsClient.DownloadGitRepoResources(newUri, destDir, token)
    if err != nil {
        return DevfileObj{}, err
    }

Litte did I know back when I examined this code about CVE-2023-49569:

CVE-2023-49569 A path traversal vulnerability was discovered in go-git versions prior to v5.11. This vulnerability allows an attacker to create and amend files across the filesystem. In the worse case scenario, remote code execution could be achieved.

This vulnerability was published on January 12th, and could have been very useful for my proposed attack as the Devfile library utilizes go-git for the underlying Git operations. However when I was looking at the Devfile library this vulnerability was not public yet. I might have found it if I had decided to dig deeper into the Git operations, but I didn't ;). Instead when I was realizing that a simple URL pointing to one of either gitlab.com, github.com, raw.githubusercontent.com or bitbucket.org, the Devfile library would do its magic and try to git clone the according repository to get the referenced files.

The relevant implementation parts are in pkg/devfile/parser/util/utils.go:

// DownloadGitRepoResources downloads the git repository resources
func (c DevfileUtilsClient) DownloadGitRepoResources(url string, destDir string, token string) error {
    var returnedErr error
    if util.IsGitProviderRepo(url) {
        gitUrl, err := util.NewGitURL(url, token)
        if err != nil {
            return err
        }
        if !gitUrl.IsFile || gitUrl.Revision == "" || !ValidateDevfileExistence((gitUrl.Path)) {
            return fmt.Errorf("error getting devfile from url: failed to retrieve %s", url)
        }
        stackDir, err := os.MkdirTemp("", "git-resources")
        if err != nil {
            return fmt.Errorf("failed to create dir: %s, error: %v", stackDir, err)
        }
        defer func(path string) {
            err := os.RemoveAll(path)
            if err != nil {
                returnedErr = multierror.Append(returnedErr, err)
            }
        }(stackDir)
        gitUrl.Token = token
        err = gitUrl.CloneGitRepo(stackDir)
        if err != nil {
            returnedErr = multierror.Append(returnedErr, err)
            return returnedErr
        }
        dir := path.Dir(path.Join(stackDir, gitUrl.Path))
        err = util.CopyAllDirFiles(dir, destDir)
        if err != nil {
            returnedErr = multierror.Append(returnedErr, err)
            return returnedErr
        }
    } else {
        return fmt.Errorf("failed to download resources from parent devfile.  Unsupported Git Provider for %s ", url)
    }
    return nil
}

and in /pkg/util/util.go:

// IsGitProviderRepo checks if the url matches a repo from a supported git provider
func IsGitProviderRepo(url string) bool {
    if strings.Contains(url, RawGitHubHost) || strings.Contains(url, GitHubHost) ||
        strings.Contains(url, GitLabHost) || strings.Contains(url, BitbucketHost) {
        return true
    }
    return false
}

So instead of digging into the go-git path here I performed some simple checks using symbolic links in repositories to see if that would bring me any further. That wasn't the case, so next I started looking into parseFromRegistry. A registry for Devfiles is based on the Open Container Initiative (OCI) Specification and pretty much behaves like for instance a Docker registry.

Diving into parseFromRegistry quickly escalated as I was confronted with just another dependency of the dependency. parseFromRegistry calls getResourcesFromRegistry which itself leaves the heavy-lifting to registryLibrary. This library, registry-support is also developed by the Devfile project and I decided to take a look at it. After following the code flow, I arrived at the PullStackFromRegistry function, which calls the decompress function, which takes a tar.gz archive from the registry library and extracts the files inside that archive. Let's have a look at that decompress function:

// decompress extracts the archive file
func decompress(targetDir string, tarFile string, excludeFiles []string) error {
    var returnedErr error
    reader, err := os.Open(filepath.Clean(tarFile))
...
    gzReader, err := gzip.NewReader(reader)
...
    tarReader := tar.NewReader(gzReader)
    for {
...
        target := path.Join(targetDir, filepath.Clean(header.Name))
        switch header.Typeflag {
...
        case tar.TypeReg:
            /* #nosec G304 -- target is produced using path.Join which cleans the dir path */
            w, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
            if err != nil {
                returnedErr = multierror.Append(returnedErr, err)
                return returnedErr
            }
            /* #nosec G110 -- starter projects are vetted before they are added to a registry.  Their contents can be seen before they are downloaded */
            _, err = io.Copy(w, tarReader)
            if err != nil {
                returnedErr = multierror.Append(returnedErr, err)
                return returnedErr
            }
            err = w.Close()
            if err != nil {
                returnedErr = multierror.Append(returnedErr, err)
                return returnedErr
            }
        default:
            log.Printf("Unsupported type: %v", header.Typeflag)
        }
    }
    return nil
}

This looked promising: the line

target := path.Join(targetDir, filepath.Clean(header.Name))

followed by:

/* #nosec G304 -- target is produced using path.Join which cleans the dir path */
w, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))

The gosec rule 304, File path provided as taint input, had alerted here and the developer had instructed the gosec scanner to ignore the finding. The comment even gives us the reasoning for this: target is produced using path.Join which cleans the dir path, which references how the filepath.Clean(header.Name) is used a little earlier in the code flow.

However filepath.Clean does not work as expected here. It's not really obvious from the documentation either, but when supplying a relative path to filepath.Clean the Clean()ed path will stay relative.

Consider the following example:

package main
import (
    "fmt"
    "path/filepath"
)
func main() {
    fmt.Println(filepath.Clean("/../../../../../../../tmp/test")) // absolute path
    fmt.Println(filepath.Clean("../../../../../../../tmp/test"))  // relative path
}

The output of this program is:

/tmp/test
../../../../../../../tmp/test

And this was the missing puzzle piece for a successful exploit. Tar files can contain /es and .s in their entry names. So we can traverse out of the intended directory and decompress and write files to arbitrary locations on disk when including a parent from a registry in the Devfile.

After this path traversal was identified a lot of time actually went into setting up a fake registry server and delivering a proper payload. In total this vulnerability, from starting to look into the Devfile Gem to having the a working exploit ready took about two working days where a lot of time was spent in setting up both the Workspaces feature and the fake registry.

Conclusions

There are several takeaways more or less hidden between the lines in this post I would like to highlight here.

Parser differentials

Parser differentials can be a very powerful tool when it comes to exploitation. They are very context dependent though and hard to generalize in their use for exploiting software.

For once the SAST scanner was right. The path traversal was not stopped by filepath.Clean, but the comment's author thought it was. They explicitly turned off the gosec warning. The whole point in software exploitation is to let some software do what it wasn't intended to do by the authors. This means when reading comments in source code they should be taken as an inspiration to think how can I falsify this comment?.

../ keeps on giving

The character sequence ../ is really a gift which keeps on giving. Path traversals most of the time are simple and reliably to exploit. They've been around 30+ years, still this vulnerability class has not yet been solved.

Can't find all the bugs

The go-git vulnerability (CVE-2023-49569) was disclosed only a few days after I internally reported the file write issue based on the registry parser. This vulnerability used in combination with the parser differential would have been another way to write files where they don't belong. The message here is kind of two fold: while it might not be possible to find all the bugs there's often enough bugs to reach your goal in a sufficiently big code base. ;)

Keep digging everyone

Finally, I'd like to highlight that to find vulnerabilities it's always worth digging into source code, reading it and trying to understand the assumptions under which it has been developed. The real hard part is to "know" where to look and when to stop looking.

{
"by": "pentestercrab",
"descendants": 0,
"id": 40249416,
"kids": [
40249456
],
"score": 3,
"time": 1714753396,
"title": "Devfile file write vulnerability in Gitlab – walkthrough finding CVE-2024-0402",
"type": "story",
"url": "https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/"
}
{
"author": null,
"date": null,
"description": null,
"image": "https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/new-workspace.png",
"logo": null,
"publisher": "GitLab Security Tech Notes",
"title": "Devfile file write vulnerability in GitLab - GitLab Security Tech Notes",
"url": "https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/"
}
{
"url": "https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/",
"title": "Devfile file write vulnerability in GitLab - GitLab Security Tech Notes",
"description": "This post is a extensive walkthrough of the process of identifying and exploiting CVE-2024-0402. The vulnerability in GitLab was fixed on January 25th 2024 with a Critical Security Release. Sometimes exploits...",
"links": [
"https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/"
],
"image": "",
"content": "<div>\n<p>This post is a extensive walkthrough of the process of identifying and exploiting\n<a target=\"_blank\" href=\"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-0402\">CVE-2024-0402</a>.</p>\n<p>The vulnerability in GitLab was fixed on January 25th 2024 with a\n<a target=\"_blank\" href=\"https://about.gitlab.com/releases/2024/01/25/critical-security-release-gitlab-16-8-1-released/#arbitrary-file-write-while-creating-workspace\">Critical Security Release</a>.</p>\n<p>Sometimes exploits for vulnerabilities are like onions: they have layers.\nThis particular exploit had several layers and two underlying vulnerabilities\nwhich were used in combination to achieve an arbitrary file write on a GitLab\ninstance. This file write then can be further abused to run arbitrary commands\non a GitLab instance. This post will cover the general approaches to identify\nsuch issues and the technical details the exploit relies upon. However we'll spare\nthe full end-to-end exploit as we deem the underlying techniques and approaches\nmuch more relevant in general than sharing an exploit for a patched vulnerability.</p>\n<h2 id=\"starting-point-dependencies\">Starting point: dependencies</h2>\n<p>The adventure started by looking at the <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/gitlab/-/blob/1fb74032a0aa55286e18428b3cedd001891555b7/Gemfile#L648\">dependencies</a>\nof the <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/gitlab\"><code>GitLab</code></a> main project.</p>\n<p>While looking for some low-hanging fruit in the project dependencies I noticed the\n<code>devfile</code> <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/ruby/gems/devfile-gem/\">Gem</a> making\n<a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/ruby/gems/devfile-gem/-/blob/1573dfa774a9d2c8f1335095c7f1ff5f7853f2d9/lib/devfile.rb#L45\">calls to an external helper binary</a>\nby using <a target=\"_blank\" href=\"https://docs.ruby-lang.org/en/2.0.0/Open3.html#method-i-capture3\"><code>Open3.capture3</code></a>.\nCalling external binaries is a typical red flag for me, there are many things\nwhich might go sideways. Command or Argument injections for example, or other\nsurprises from lesser known features of the called binary. Not to speak of actual\nvulnerabilities in the binary or its dependencies.</p>\n<p>Notably the <code>devfile</code> Gem is written <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/ruby/gems/devfile-gem/\">in-house at GitLab</a>.\nA quick review of the repository revealed <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/ruby/gems/devfile-gem/-/blob/1573dfa774a9d2c8f1335095c7f1ff5f7853f2d9/ext/\">some Go based code</a>\nfrom which the <code>devfile</code> binary called by the Ruby Gem was being created. I didn't\nknow much about <a target=\"_blank\" href=\"https://devfile.io/\">Devfiles</a> at this point. I only had the\nvague concept in the back of my head that those were YAML files used to describe\nthe environments for <a target=\"_blank\" href=\"https://docs.gitlab.com/ee/user/workspace/\">GitLab's Workspaces</a>\nfeature.</p>\n<p>Workspaces are isolated web-based development environments which are deployed by\nthe GitLab application into Kubernetes clusters. Zooming out a bit we have:</p>\n<ul>\n<li>Devfiles: YAML files which are used to describe Workspaces in Kubernetes environments</li>\n<li>A Ruby library which parses those devfiles by calling a Go based helper binary</li>\n</ul>\n<p>A quick check of the <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/ruby/gems/devfile-gem/-/blob/1573dfa774a9d2c8f1335095c7f1ff5f7853f2d9/lib/devfile.rb#L45\">Ruby code calling the Go binary</a>\nshowed there were no surprises or low hanging fruits. The binary is being\ncalled directly with no shell being involved, simple command injections were not\npossible. Also the Go binary had no opportunity for Argument injections.</p>\n<h2 id=\"digging-deeper\">Digging deeper</h2>\n<p>Sometimes it's great to just start messing around with a software to get\na feeling for potential vulnerabilities. The design of the <code>devfile</code> Gem\nmade this easy. I could just use the included Go based binary and feed it\nsome YAML. Digging into the <a target=\"_blank\" href=\"https://devfile.io/docs/\">documentation</a>\nand looking for some sample files to use I came across the <a target=\"_blank\" href=\"https://devfile.io/docs/2.2.2/referring-to-a-parent-devfile\"><code>parent</code></a>\nfeature which allows another <code>devfile</code> to be specified. That file is then used as a\nbase for your current <code>devfile</code>. I used the example from the\n<a target=\"_blank\" href=\"https://devfile.io/docs/2.2.2/referring-to-a-parent-devfile#parent-referred-by-uri\">documentation</a>\nwith the <code>devfile</code> binary in the Gem like so:</p>\n<pre><code>joern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ ls\ndevfile\njoern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ ./devfile flatten 'schemaVersion: 2.2.0\nmetadata:\n name: my-project-dev\nparent:\n uri: https://raw.githubusercontent.com/devfile/registry/main/stacks/nodejs/devfile.yaml'\nfailed to populateAndParseDevfile: error getting devfile info from url: failed to retrieve https://raw.githubusercontent.com/devfile/registry/main/stacks/nodejs/devfile.yaml, 404: Not Foundjoern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ \n</code></pre>\n<p>I was quite surprised when I did a <code>ls</code> in the directory after that command:</p>\n<pre><code>joern@host2:~/projects/deps/ruby/3.2.0/gems/devfile-0.0.25.pre.alpha1-x86_64-linux/bin$ ls\n2.1.1 2.2.0 devfile OWNERS stack.yaml\n</code></pre>\n<p>A directory from the <a target=\"_blank\" href=\"https://github.com/devfile/registry/tree/main/stacks/nodejs\"><code>devfile/registry</code> repository</a>\nhas been copied into the working directory where I ran the <code>./devfile</code> command.\nThis was the moment I figured I might be on to something worth spending some\nmore time on.</p>\n<h2 id=\"one-step-back-and-three-steps-forward\">One step back and three steps forward</h2>\n<p>The <code>I'll copy some stuff from the Internet into your working directory when you\nparse a devfile</code> thing was very promising. I was hoping to use this vector to\ngain an arbitrary file write from it. Should be easy enough, all I needed to do\nwas to figure out the code path from within GitLab to trigger the dependency to\nflatten a devfile I crafted. That, and yes maybe a traversal out of the working\ndirectory, maybe not. That would depend on my current unknowns where on a GitLab\ninstance this working directory would be and what I would control in terms of\nwritten files. But overall, this issue looked like a juicy starting place.</p>\n<p>So I took a deeper dive into the <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/gitlab\">main Ruby on Rails codebase of GitLab</a>,\njust to find out that there's a validation to prevent the usage of that\n<code>parent</code> feature in a <code>devfile</code>. This was really inconvenient, I almost saw that\nawesome file write vanish in <a target=\"_blank\" href=\"https://gitlab.com/gitlab-org/gitlab/-/blob/426689d290f0a7f86f2f01298e974c433ff235fb/ee/lib/remote_development/workspaces/create/pre_flatten_devfile_validator.rb#L53\">that line of code</a>:</p>\n<pre><code>return err(_(\"Inheriting from 'parent' is not yet supported\")) if devfile['parent']\n</code></pre>\n<p>But it wasn't really that bad, this roadblock was something for which I was\nprepared. In May 2023 I was \"messing\" with YAML files. This was\ninspired by a <a target=\"_blank\" href=\"https://bishopfox.com/blog/json-interoperability-vulnerabilities\">blog post from Jake Miller</a>\nabout parser differentials in JSON parsers, as JSON and YAML are somewhat similar\nin their use cases, but YAML is a bit more complex I thought it might be worthwhile\nlooking at YAML from a parser differential perspective. <a target=\"_blank\" href=\"https://threatactor.club/@joern/statuses/01H151R43VF3HNZR4G05HP9CP8\">Back then</a>\nI was able to craft a YAML file which would parse differently in Ruby and Python.\nHowever it would parse the same in Ruby and in Go, so I \"just\" needed to find\na similar parser differential in Go and in Ruby. Let's first look at the initial\nYAML file targeting Ruby/Go vs. Python:</p>\n<pre><code>joern@host2:~/projects/devfile$ cat 1.yaml \ntest: python\n!!binary dGVzdA==: ruby &amp; go\njoern@host2:~/projects/devfile$ python -c 'import yaml;x = yaml.safe_load(open(\"1.yaml\"));print(x[\"test\"])'\npython\njoern@host2:~/projects/devfile$ ruby -ryaml -e 'x = YAML.safe_load(File.read(\"1.yaml\"));puts x[\"test\"]'\nruby &amp; go\njoern@host2:~/projects/devfile$ cat g.go \npackage main\nimport (\n \"fmt\"\n \"log\"\n \"os\"\n \"gopkg.in/yaml.v3\"\n)\nfunc main() {\n data, _ := os.ReadFile(os.Args[1])\n unmarshalled := &amp;yaml.Node{}\n err := yaml.Unmarshal([]byte(data), unmarshalled)\n if err != nil {\n log.Fatalf(\"error: %v\", err)\n }\n var expanded interface{}\n err = unmarshalled.Content[0].Decode(&amp;expanded)\n if err != nil {\n log.Fatalf(\"error: %v\", err)\n }\n d, err := yaml.Marshal(expanded)\n if err != nil {\n log.Fatalf(\"error: %v\", err)\n }\n fmt.Printf(\"%s\\n\", string(d))\n}\njoern@host2:~/projects/devfile$ go run g.go 1.yaml\ntest: ruby &amp; go\n</code></pre>\n<p>The very simple \"secret sauce\" here is using the <a target=\"_blank\" href=\"https://yaml.org/type/binary.html\"><code>!!binary</code></a>\nnotation to introduce a Base64 encoded key:</p>\n<pre><code>test: python\n!!binary dGVzdA==: ruby &amp; go\n</code></pre>\n<p>The Base64 (<code>!!binary</code>) string <code>dGVzdA==</code> becomes <code>test</code> when being decoded.\nIn Ruby and in Go this will overwrite the previously defined <code>test: python</code> value.\nBut in Python the following will happen:</p>\n<pre><code>python -c 'import yaml;y = yaml.safe_load(open(\"1.yaml\"));print(y)' \n{'test': 'python', b'test': 'ruby &amp; go'}\n</code></pre>\n<p>The <code>!!binary</code> notation will create a <a target=\"_blank\" href=\"https://docs.python.org/3/library/stdtypes.html#binary-sequence-types-bytes-bytearray-memoryview\">Binary Sequence</a>\n(<code>b'test'</code>) in Python which is different from the string <code>test</code>. So we'll have\ntwo keys, <code>test</code> and <code>b'test'</code> here, instead of one overwriting the other like\nit happens in Ruby and Go.</p>\n<p>This behavior was the base I had ready, would GitLab have been a Python\ncode base with the same Go parser backend this would've been ready to\nuse right away to bypass the <code>parent</code> key filtering. Unfortunately this isn't\nthe case so I had to find a different way to bypass the key filter.</p>\n<p>I spent a bit of time reading about <a target=\"_blank\" href=\"https://yaml.org/spec/1.2.2/#3212-tags\">Tags in YAML</a>\nand noticed the line <code>Local tags start with “!”</code>. Well OK then I thought, let's\njust try and see what happens when I use <code>!binary</code> instead of <code>!!binary</code>:</p>\n<pre><code>joern@host2:~/projects/devfile$ cat 2.yaml\ntest: non-binary \n!binary dGVzdA==: binary\njoern@host2:~/projects/devfile$ ruby -ryaml -e 'x = YAML.safe_load(File.read(\"2.yaml\"));puts x'\n{\"test\"=&gt;\"binary\"}\njoern@host2:~/projects/devfile$ go run g.go 2.yaml\ndGVzdA==: binary\ntest: non-binary\njoern@host2:~/projects/devfile$ \n</code></pre>\n<p>Yes, it really was that \"easy\". Having this <code>!binary</code> behavior difference in Ruby and Go we\ncan construct a YAML file like:</p>\n<pre><code>whatever: is here\n!binary parent: hehehe injected\n</code></pre>\n<p>Now when we look at it through the eyes of Ruby it will appear as:</p>\n<pre><code>joern@host2:~/projects/devfile$ ruby -ryaml -e 'x = YAML.safe_load(File.read(\"what.yaml\"));puts x'\n{\"whatever\"=&gt;\"is here\", \"\\xA5\\xAA\\xDE\\x9E\"=&gt;\"hehehe injected\"}\n</code></pre>\n<p>The <code>!binary</code> value has been decoded to a binary key <code>\"\\xA5\\xAA\\xDE\\x9E\"</code> and now,\n<strong>drumroll</strong> for the Go parser:</p>\n<pre><code>joern@host2:~/projects/devfile$ go run g.go what.yaml \nparent: hehehe injected\nwhatever: is here\n</code></pre>\n<p>The <code>!binary</code> tag has just been silently dropped and the resulting YAML\nkey is called <code>parent</code>. These two behaviors combined are exactly what we need\nto bypass the Ruby validation for the <code>parent</code> key in the Devfile YAML.</p>\n<h2 id=\"writing-files-where-they-dont-belong\">Writing files where they don't belong</h2>\n<p>Now that we're able to sneak the <code>parent</code> key past Ruby and into\nthe Go code it is time to dig deeper into the devfile library and\nthe odd file writing behavior to the working directory I noticed earlier.</p>\n<p>First of all, I wanted to know where that working directory was when the\n<code>devfile</code> binary from the Gem was called on a GitLab instance. I was hoping\nthat it would be somewhat useful directory from an exploitation perspective.</p>\n<p>To find this out I looked at the <a target=\"_blank\" href=\"https://docs.gitlab.com/ee/user/workspace/configuration.html#set-up-a-workspace\">documentation howto set up GitLab Workspaces</a>.\nThere's quite a lot of requirements here to set up those Workspaces properly,\na Kubernetes Cluster and a GitLab Agent for it, as well as certain configuration\nprojects on the GitLab instance to set up and tie everything together. The TL;DR\nof my test setup was to run everything locally. GitLab was run using Docker\nand the Kubernetes side was set up with <a target=\"_blank\" href=\"https://minikube.sigs.k8s.io/\"><code>minikube</code></a>.</p>\n<p>With those two pieces in place we can connect the <code>minkube</code> cluster with the\n<a target=\"_blank\" href=\"https://docs.gitlab.com/ee/user/clusters/agent/\">GitLab Agent</a> to a project\nin a group on the GitLab instance. In another within the same group we can\nthen create a <code>.devfile.yaml</code> with the following content:</p>\n<pre><code>schemaVersion: 2.2.0\n!binary parent: \n uri: https://raw.githubusercontent.com/devfile/registry/main/stacks/nodejs/devfile.yaml'\n</code></pre>\n<p>To trigger the Devfile parsing we now just need to create a workspace for that\nproject:</p>\n<p><img alt=\"new workspace\" src=\"https://gitlab-com.gitlab.io/gl-security/security-tech-notes/security-research-tech-notes/devfile/new-workspace.png\" /></p>\n<p>After this step I logged into the GitLab Docker container and searched for the\nfile <code>stack.yaml</code> which was present when I parsed the same Devfile earlier when\nI initially observed the file writing behavior.</p>\n<pre><code>root@localhost:/# find . -name stack.yaml 2&gt; /dev/null \n./var/opt/gitlab/gitlab-rails/working/stack.yaml\nroot@localhost:/# cd /var/opt/gitlab/gitlab-rails/working/\nroot@localhost:/var/opt/gitlab/gitlab-rails/working# ls -lart\ntotal 46\ndrwxr-xr-x 9 git root 12 Apr 11 12:59 ..\n-rw-r--r-- 1 git git 283 Apr 12 13:09 stack.yaml\n-rw-r--r-- 1 git git 73 Apr 12 13:09 OWNERS\ndrwxr-xr-x 2 git git 2 Apr 12 13:09 2.2.0\ndrwxr-xr-x 2 git git 2 Apr 12 13:09 2.1.1\ndrwx------ 4 git root 6 Apr 12 13:09 .\n</code></pre>\n<p>This result was not very promising, the directory was empty besides the files\nwritten via the Devfile parser. While there might be some race conditions with\nother parts of GitLab where we could write into temporary directories I decided\nto not go down this route and instead dig deeper into the <a target=\"_blank\" href=\"https://github.com/devfile/library\">Devfile library</a>.</p>\n<p>The main logic which parses the <code>parent</code> key in the Devfile was quickly\nidentified. It starts in <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L301\"><code>parseParentAndPlugin()</code></a>.\nThe name of the function already indicates another similar feature comparable to\n<code>parent</code>, namely the <a target=\"_blank\" href=\"https://devfile.io/docs/2.0.0/adding-plugin-component\"><code>plugin</code></a>.\nAs both features, <code>parent</code> and <code>plugin</code> had pretty much the same underlying logic\nin a switch statement for <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L381-L390\"><code>plugin</code></a>\nand for <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L320-L328\"><code>parent</code></a>:</p>\n<pre><code>switch {\ncase parent.Uri != \"\":\n parentDevfileObj, err = parseFromURI(parent.ImportReference, d.Ctx, resolveCtx, tool)\ncase parent.Id != \"\":\n parentDevfileObj, err = parseFromRegistry(parent.ImportReference, resolveCtx, tool)\ncase parent.Kubernetes != nil:\n parentDevfileObj, err = parseFromKubeCRD(parent.ImportReference, resolveCtx, tool)\ndefault:\n return fmt.Errorf(\"devfile parent does not define any resources\")\n}\n</code></pre>\n<p>I digged deeper into the <code>parseFrom*</code> methods. At first I looked into\n<code>parseFromURI</code>, a URI to download a Devfile from I thought, should be easy enough.\nSurprisingly it was not that easy. The <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L442-L503\"><code>parseFromURI</code> function</a>\nhad quite some logic involved about local and remote URLs. What caught\nmy attention <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L491-L496\">was</a>:</p>\n<pre><code>if tool.downloadGitResources {\n destDir := path.Dir(curDevfileCtx.GetAbsPath())\n err = tool.devfileUtilsClient.DownloadGitRepoResources(newUri, destDir, token)\n if err != nil {\n return DevfileObj{}, err\n }\n</code></pre>\n<p>Litte did I know back when I examined this code about <a target=\"_blank\" href=\"https://nvd.nist.gov/vuln/detail/CVE-2023-49569\">CVE-2023-49569</a>:</p>\n<blockquote>\n<p>CVE-2023-49569\nA path traversal vulnerability was discovered in go-git versions prior to v5.11. This vulnerability allows an attacker to create and amend files across the filesystem. In the worse case scenario, remote code execution could be achieved.</p>\n</blockquote>\n<p>This vulnerability was published on January 12th, and could have been very useful\nfor my proposed attack as the Devfile library utilizes <code>go-git</code> for the underlying\nGit operations. However when I was looking at the Devfile library this vulnerability\nwas not public yet. I <em>might</em> have found it if I had decided to dig deeper into the\nGit operations, but I didn't ;). Instead when I was realizing that a simple URL\npointing to one of either <code>gitlab.com</code>, <code>github.com</code>, <code>raw.githubusercontent.com</code>\nor <code>bitbucket.org</code>, the Devfile library would do its magic and try to <code>git clone</code>\nthe according repository to get the referenced files.</p>\n<p>The relevant implementation parts are in <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/main/pkg/devfile/parser/util/utils.go#L47\">pkg/devfile/parser/util/utils.go</a>:</p>\n<pre><code>// DownloadGitRepoResources downloads the git repository resources\nfunc (c DevfileUtilsClient) DownloadGitRepoResources(url string, destDir string, token string) error {\n var returnedErr error\n if util.IsGitProviderRepo(url) {\n gitUrl, err := util.NewGitURL(url, token)\n if err != nil {\n return err\n }\n if !gitUrl.IsFile || gitUrl.Revision == \"\" || !ValidateDevfileExistence((gitUrl.Path)) {\n return fmt.Errorf(\"error getting devfile from url: failed to retrieve %s\", url)\n }\n stackDir, err := os.MkdirTemp(\"\", \"git-resources\")\n if err != nil {\n return fmt.Errorf(\"failed to create dir: %s, error: %v\", stackDir, err)\n }\n defer func(path string) {\n err := os.RemoveAll(path)\n if err != nil {\n returnedErr = multierror.Append(returnedErr, err)\n }\n }(stackDir)\n gitUrl.Token = token\n err = gitUrl.CloneGitRepo(stackDir)\n if err != nil {\n returnedErr = multierror.Append(returnedErr, err)\n return returnedErr\n }\n dir := path.Dir(path.Join(stackDir, gitUrl.Path))\n err = util.CopyAllDirFiles(dir, destDir)\n if err != nil {\n returnedErr = multierror.Append(returnedErr, err)\n return returnedErr\n }\n } else {\n return fmt.Errorf(\"failed to download resources from parent devfile. Unsupported Git Provider for %s \", url)\n }\n return nil\n}\n</code></pre>\n<p>and in <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/main/pkg/util/util.go#L892\">/pkg/util/util.go</a>:</p>\n<pre><code>// IsGitProviderRepo checks if the url matches a repo from a supported git provider\nfunc IsGitProviderRepo(url string) bool {\n if strings.Contains(url, RawGitHubHost) || strings.Contains(url, GitHubHost) ||\n strings.Contains(url, GitLabHost) || strings.Contains(url, BitbucketHost) {\n return true\n }\n return false\n}\n</code></pre>\n<p>So instead of digging into the <code>go-git</code> path here I performed some simple\nchecks using symbolic links in repositories to see if that would bring me any\nfurther. That wasn't the case, so next I started looking into <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L505\"><code>parseFromRegistry</code></a>. A <a target=\"_blank\" href=\"https://devfile.io/docs/2.1.0/understanding-a-devfile-registry\">registry</a>\nfor Devfiles is based on the Open Container Initiative (OCI) Specification and pretty\nmuch behaves like for instance a Docker registry.</p>\n<p>Diving into <code>parseFromRegistry</code> quickly escalated as I was confronted with just\nanother dependency of the dependency. <code>parseFromRegistry</code> calls <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L568\"><code>getResourcesFromRegistry</code></a>\nwhich itself <a target=\"_blank\" href=\"https://github.com/devfile/library/blob/v2.2.1/pkg/devfile/parser/parse.go#L575\">leaves the heavy-lifting</a>\nto <code>registryLibrary</code>. <a target=\"_blank\" href=\"https://github.com/devfile/registry-support\">This library</a>,\n<code>registry-support</code> is also developed by the Devfile project and I decided to\ntake a look at it. After following the code flow, I arrived at the <a target=\"_blank\" href=\"https://github.com/devfile/registry-support/blob/47b3ffaeadba7babb7075e0576584cfaa3f64341/registry-library/library/library.go#L295\"><code>PullStackFromRegistry</code></a>\nfunction, which calls\nthe <a target=\"_blank\" href=\"https://github.com/devfile/registry-support/blob/47b3ffaeadba7babb7075e0576584cfaa3f64341/registry-library/library/util.go#L76\"><code>decompress</code></a>\nfunction, which takes a <code>tar.gz</code> archive from the registry\nlibrary and extracts the files inside that archive. Let's have a look\nat that <code>decompress</code> function:</p>\n<pre><code>// decompress extracts the archive file\nfunc decompress(targetDir string, tarFile string, excludeFiles []string) error {\n var returnedErr error\n reader, err := os.Open(filepath.Clean(tarFile))\n...\n gzReader, err := gzip.NewReader(reader)\n...\n tarReader := tar.NewReader(gzReader)\n for {\n...\n target := path.Join(targetDir, filepath.Clean(header.Name))\n switch header.Typeflag {\n...\n case tar.TypeReg:\n /* #nosec G304 -- target is produced using path.Join which cleans the dir path */\n w, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))\n if err != nil {\n returnedErr = multierror.Append(returnedErr, err)\n return returnedErr\n }\n /* #nosec G110 -- starter projects are vetted before they are added to a registry. Their contents can be seen before they are downloaded */\n _, err = io.Copy(w, tarReader)\n if err != nil {\n returnedErr = multierror.Append(returnedErr, err)\n return returnedErr\n }\n err = w.Close()\n if err != nil {\n returnedErr = multierror.Append(returnedErr, err)\n return returnedErr\n }\n default:\n log.Printf(\"Unsupported type: %v\", header.Typeflag)\n }\n }\n return nil\n}\n</code></pre>\n<p>This looked promising: the line</p>\n<pre><code>target := path.Join(targetDir, filepath.Clean(header.Name))\n</code></pre>\n<p>followed by:</p>\n<pre><code>/* #nosec G304 -- target is produced using path.Join which cleans the dir path */\nw, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))\n</code></pre>\n<p>The <a target=\"_blank\" href=\"https://securego.io/docs/rules/g304.html\">gosec rule 304</a>,\n<code>File path provided as taint input</code>, had alerted here and the developer had \ninstructed the gosec scanner to ignore the finding. The comment even gives us\nthe reasoning for this:\n<code>target is produced using path.Join which cleans the dir path</code>, which\nreferences how the <code>filepath.Clean(header.Name)</code> is used a little earlier in the code\nflow.</p>\n<p>However <a target=\"_blank\" href=\"https://pkg.go.dev/path/filepath#Clean\"><code>filepath.Clean</code></a> does not work\nas expected here. It's not really obvious from the documentation either, but when\nsupplying a relative path to <code>filepath.Clean</code> the <code>Clean()</code>ed path will stay relative.</p>\n<p>Consider the following example:</p>\n<pre><code>package main\nimport (\n \"fmt\"\n \"path/filepath\"\n)\nfunc main() {\n fmt.Println(filepath.Clean(\"/../../../../../../../tmp/test\")) // absolute path\n fmt.Println(filepath.Clean(\"../../../../../../../tmp/test\")) // relative path\n}\n</code></pre>\n<p>The output of this program is:</p>\n<pre><code>/tmp/test\n../../../../../../../tmp/test\n</code></pre>\n<p>And this was the missing puzzle piece for a successful exploit. Tar files\ncan contain <code>/</code>es and <code>.</code>s in their entry names. So we can traverse out of\nthe intended directory and decompress and write files to arbitrary locations\non disk when including a <code>parent</code> from a registry in the Devfile.</p>\n<p>After this path traversal was identified a lot of time actually went into\nsetting up a fake registry server and delivering a proper payload. In total\nthis vulnerability, from starting to look into the Devfile Gem to having the\na working exploit ready took about two working days where a lot of time was\nspent in setting up both the Workspaces feature and the fake registry.</p>\n<h2 id=\"conclusions\">Conclusions</h2>\n<p>There are several takeaways more or less hidden between the lines\nin this post I would like to highlight here.</p>\n<h3 id=\"parser-differentials\">Parser differentials</h3>\n<p>Parser differentials can be a very powerful tool when it comes\nto exploitation. They are very context dependent though and hard\nto generalize in their use for exploiting software.</p>\n<p>For once the SAST scanner was right. The path traversal was not stopped\nby <code>filepath.Clean</code>, but the comment's author <a target=\"_blank\" href=\"https://github.com/devfile/registry-support/blob/47b3ffaeadba7babb7075e0576584cfaa3f64341/registry-library/library/util.go#L124\">thought it was</a>.\nThey explicitly turned off the gosec warning. The whole point in software exploitation\nis to let some software do what it wasn't intended to do by the authors.\nThis means when reading comments in source code they should be taken as\nan inspiration to think <code>how can I falsify this comment?</code>.</p>\n<h3 id=\"keeps-on-giving\"><code>../</code> keeps on giving</h3>\n<p>The character sequence <code>../</code> is really a gift which keeps on giving.\nPath traversals most of the time are simple and reliably to exploit.\nThey've been around 30+ years, still this vulnerability class has not\nyet been solved.</p>\n<h3 id=\"cant-find-all-the-bugs\">Can't find all the bugs</h3>\n<p>The go-git vulnerability (<a target=\"_blank\" href=\"https://nvd.nist.gov/vuln/detail/CVE-2023-49569\">CVE-2023-49569</a>)\nwas disclosed only a few days after I internally reported the file write\nissue based on the registry parser. This vulnerability used in combination\nwith the parser differential would have been another way to write files\nwhere they don't belong. The message here is kind of two fold: while it might\nnot be possible to find all the bugs there's often enough bugs to reach\nyour goal in a sufficiently big code base. ;)</p>\n<h3 id=\"keep-digging-everyone\">Keep digging everyone</h3>\n<p>Finally, I'd like to highlight that to find vulnerabilities\nit's always worth digging into source code, reading it and trying to understand the\nassumptions under which it has been developed. The real hard part is to \"know\"\nwhere to look and when to stop looking.</p></div>",
"author": "",
"favicon": "https://gitlab-com.gitlab.io/gl-security/security-tech-notes/img/favicon.ico",
"source": "gitlab-com.gitlab.io",
"published": "",
"ttr": 619,
"type": ""
}