---
title: "gookit/config: negative index panic fixed in Go | VulCode"
description: "A fix to gookit/config, a Go configuration library: a negative index in a key path no longer panics in GetValue and Exists and is reported as not found."
url: "https://vulcode.com/en/opensource/contributions/gookit-config"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

gookit/config

# gookit/config

A Go library for loading and reading configuration from JSON, YAML, TOML, INI, environment variables and flags, with access to values by key path.

[See the repository](https://github.com/gookit/config) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 584
- **Merged changes**: 1

## What we changed

A negative index in a key path, such as arr.-1, no longer panics in GetValue or Exists and is reported as not found.

### What this work shows

- Index bounds checking in Go

- Hardening against user input

- Panic tests in Go

What was broken

### arr.-1 crashed the program

GetValue("arr.-1") and Exists("arr.-1") ended in an index out of range [-1] panic. strconv.Atoi accepts "-1", and the checks in read.go only tested the upper bound of the slice.

How we fixed it

### A lower bound in six places

We added an i < 0 check to every index guard for []int, []string and []any in GetValue and Exists, so a negative index means no value. A test checks that both calls do not panic and report not found.

[#221](https://github.com/gookit/config/pull/221)

## Merged change 1

- [#221 fix(read): prevent panic on negative slice index in a key path Merged 7 September 2026](https://github.com/gookit/config/pull/221)

## What it taught us

Key paths often come from users or from configuration, so every index taken from one must be checked on both sides before use. A missing lower bound was enough for a single minus sign to crash the whole program.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
