mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-05 23:05:45 +00:00
fix: prevent masking gaps in workflow command logs (#1384)
Mask partially escaped workflow command output and complete one-character values while preserving literal output and stream line endings. Fixes: https://gitea.com/gitea/runner/issues/300 Reviewed-on: https://gitea.com/gitea/runner/pulls/1384 Reviewed-by: bircni <[email protected]>
This commit is contained in:
1 parent
ee03687688
commit
95ef17d022
6 files changed
+123
-20
No files matched your search
@@ -960,7 +960,7 @@ func logRow(entry logging.Record) *runnerv1.LogRow {
|
||||
|
||||
// mask repairs the content first, so a secret the repair itself spells out is still caught.
|
||||
func (r *Reporter) mask(content string) string {
|
||||
return r.logReplacer.Replace(strings.ToValidUTF8(content, "?"))
|
||||
return runner.MaskLog(strings.ToValidUTF8(content, "?"), r.logReplacer)
|
||||
}
|
||||
|
||||
// AddMask deliberately leaves the process-wide masker alone. Its entries come from every live
|
||||
|
||||
@@ -750,8 +750,7 @@ func TestReporter_ParseResult(t *testing.T) {
|
||||
func TestReporter_masksEncodedSecrets(t *testing.T) {
|
||||
secret := `p@ss w"rd/1`
|
||||
r := &Reporter{logReplacer: strings.NewReplacer()}
|
||||
r.oldnew = runner.AppendSecretMasker(r.oldnew, secret)
|
||||
r.logReplacer = strings.NewReplacer(r.oldnew...)
|
||||
r.AddMask(secret)
|
||||
|
||||
for _, line := range []string{
|
||||
"token: " + secret,
|
||||
@@ -763,6 +762,17 @@ func TestReporter_masksEncodedSecrets(t *testing.T) {
|
||||
assert.NotContains(t, masked, secret)
|
||||
assert.NotContains(t, masked, base64.StdEncoding.EncodeToString([]byte(secret)))
|
||||
}
|
||||
|
||||
r.AddMask("alpha beta;gamma]delta")
|
||||
r.AddMask("%")
|
||||
for _, test := range []struct{ line, want string }{
|
||||
{"##[group]alpha beta%3Bgamma%5Ddelta", "##[group]***"},
|
||||
{"##[group]alpha beta%3Bgamma]delta", "##[group]***"},
|
||||
{"%", "***"},
|
||||
} {
|
||||
r.appendLogRow(logRow(logging.Record{Message: test.line}))
|
||||
assert.Equal(t, test.want, r.logRows[len(r.logRows)-1].Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReporter_AckIndexBeyondBuffer(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user