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 - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.25 go-version: 1.24
- name: Build - name: Build
run: go build ./... run: go build ./...
+16 -5
View File
@@ -1,3 +1,5 @@
version: 2
project_name: gitleaks project_name: gitleaks
builds: builds:
@@ -15,17 +17,26 @@ builds:
goarm: goarm:
- "6" - "6"
- "7" - "7"
ignore:
- goos: windows
goarch: arm
tags: tags:
- gore2regex - gore2regex
ldflags: ldflags:
- -s -w -X=github.com/zricethezav/gitleaks/v8/version.Version={{.Version}} - -s -w -X=github.com/zricethezav/gitleaks/v8/version.Version={{.Version}}
archives: 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: format_overrides:
- goos: windows - goos: windows
format: zip formats: [zip]
replacements:
amd64: x64
386: x32
release: release:
prerelease: true 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 WORKDIR /go/src/github.com/zricethezav/gitleaks
COPY . . COPY . .
RUN VERSION=$(git describe --tags --abbrev=0) && \ RUN VERSION=$(git describe --tags --abbrev=0) && \
+2 -1
View File
@@ -3,8 +3,9 @@ package codec
import ( import (
"fmt" "fmt"
"math" "math"
"regexp"
"strings" "strings"
"github.com/zricethezav/gitleaks/v8/regexp"
) )
var ( var (
+2 -1
View File
@@ -2,10 +2,11 @@ package codec
import ( import (
"bytes" "bytes"
"regexp"
"strconv" "strconv"
"strings" "strings"
"unicode/utf8" "unicode/utf8"
"github.com/zricethezav/gitleaks/v8/regexp"
) )
var ( var (
+1 -1
View File
@@ -1,6 +1,6 @@
module github.com/zricethezav/gitleaks/v8 module github.com/zricethezav/gitleaks/v8
go 1.25.4 go 1.24.11
require ( require (
github.com/BobuSumisu/aho-corasick v1.0.3 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. // TODO: Add helper functions like escaping for JSON, XML, etc.
t := template.New("custom") 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) t, err = t.Parse(templateText)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing file: %w", err) 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)
}
})
}
}