Skip to content

Insecure: color string injection #8

@dolmen

Description

@dolmen

In Sprintf-like functions, colors tags expansion should only happen in format strings, not on the Sprintf-expanded output. This is because the argument values may contain uncontrolled content where the expansion of {{ }} tags could be used to hide malicious strings.

Here is a simple program that is insecure because of cfmt:

package main

import (
	"os"

	"github.com/i582/cfmt/cmd/cfmt"
)

func main() {
	cfmt.EnableColors()
	cfmt.Printf("Hello {{%q}}::blue|bold\n", os.Args[1])
}
$ go run . world                                       
Hello "world"
$ go run . '}}::blue|bold{{Pwned!}}::red|bold|blink{{'
Hello "Pwned!"

Affected functions:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions