Compare commits

...
4 Commits
Author SHA1 Message Date
Zach 83d9cd684c update goreleaser 2026-03-12 10:40:37 -05:00
Fatih Çelik 8d1f98c796 Removed unnecessary functions from report template (#2040) 2026-02-21 07:30:12 -06:00
Zachary Rice ca20267a84 its the simple things (#2020) 2026-01-08 14:48:47 -06:00
Richard Gomez b66ac75e4f build: switch to Go 1.24 (#2002) 2025-12-09 09:15:58 -06:00
8 changed files with 79 additions and 11 deletions

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.25
go-version: 1.24
- name: Build
run: go build ./...
+16 -5
View File
@@ -1,3 +1,5 @@
version: 2
project_name: gitleaks
builds:
@@ -15,17 +17,26 @@ builds:
goarm:
- "6"
- "7"
ignore:
- goos: windows
goarch: arm
tags:
- gore2regex
ldflags:
- -s -w -X=github.com/zricethezav/gitleaks/v8/version.Version={{.Version}}
archives:
- builds: [gitleaks]
- ids: [gitleaks]
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- .Os }}_
{{- if eq .Arch "amd64" }}x64
{{- else if eq .Arch "386" }}x32
{{- else }}{{ .Arch }}{{ end }}
{{- with .Arm }}v{{ . }}{{ end }}
format_overrides:
- goos: windows
format: zip
replacements:
amd64: x64
386: x32
formats: [zip]
release:
prerelease: true
+1 -1
View File
@@ -1,4 +1,4 @@
FROM golang:1.25 AS build
FROM golang:1.24 AS build
WORKDIR /go/src/github.com/zricethezav/gitleaks
COPY . .
RUN VERSION=$(git describe --tags --abbrev=0) && \
+2 -1
View File
@@ -3,8 +3,9 @@ package codec
import (
"fmt"
"math"
"regexp"
"strings"
"github.com/zricethezav/gitleaks/v8/regexp"
)
var (
+2 -1
View File
@@ -2,10 +2,11 @@ package codec
import (
"bytes"
"regexp"
"strconv"
"strings"
"unicode/utf8"
"github.com/zricethezav/gitleaks/v8/regexp"
)
var (
+1 -1
View File
@@ -1,6 +1,6 @@
module github.com/zricethezav/gitleaks/v8
go 1.25.4
go 1.24.11
require (
github.com/BobuSumisu/aho-corasick v1.0.3
+7 -1
View File
@@ -29,7 +29,13 @@ func NewTemplateReporter(templatePath string) (*TemplateReporter, error) {
// TODO: Add helper functions like escaping for JSON, XML, etc.
t := template.New("custom")
t = t.Funcs(sprig.TxtFuncMap())
funcMap := sprig.TxtFuncMap()
delete(funcMap, "env")
delete(funcMap, "expandenv")
delete(funcMap, "getHostByName")
t = t.Funcs(funcMap)
t, err = t.Parse(templateText)
if err != nil {
return nil, fmt.Errorf("error parsing file: %w", err)
+49
View File
@@ -96,3 +96,52 @@ func TestWriteTemplate(t *testing.T) {
})
}
}
func TestTemplateDangerousFunctions(t *testing.T) {
tests := []struct {
name string
template string
wantErr string
}{
{
name: "env is blocked",
template: `{{ env "SECRET" }}`,
wantErr: `function "env" not defined`,
},
{
name: "expandenv is blocked",
template: `{{ expandenv "$SECRET" }}`,
wantErr: `function "expandenv" not defined`,
},
{
name: "getHostByName is blocked",
template: `{{ getHostByName "localhost" }}`,
wantErr: `function "getHostByName" not defined`,
},
{
name: "now is allowed (benign)",
template: `{{ now | date "2006-01-02" }}`,
wantErr: "", // should not error on parse
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpfile, err := os.CreateTemp(t.TempDir(), "test*.tmpl")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
_, err = tmpfile.WriteString(tt.template)
require.NoError(t, err)
tmpfile.Close()
_, err = NewTemplateReporter(tmpfile.Name())
if tt.wantErr != "" {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
} else {
assert.NoError(t, err)
}
})
}
}