Rules / Go
SHIELD-GO-012
Use of deprecated ioutil package
What it detects
ioutil functions are deprecated since Go 1.16 and should use io/os equivalents.
How to fix
Replace ioutil functions with their io or os equivalents (e.g., io.ReadAll, os.ReadFile).
Vulnerable — Shield flags thismain.go
package main
import (
"fmt"
"io/ioutil"
)
func main() {
data, err := ioutil.ReadFile("config.yaml")
if err != nil {
panic(err)
}
fmt.Println(string(data))
}Fixed — scans cleanmain.go
package main
import (
"fmt"
"os"
)
func main() {
data, err := os.ReadFile("config.yaml")
if err != nil {
panic(err)
}
fmt.Println(string(data))
}Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-GO-012, the fixed one does not.