fix: secret name-prefix regex (#12213)

Fixes: #12212
Sorry for this bug, I introduced it by not testing !10682 better. Now the `forbiddenPrefixPattern`-regex is compliant to the docu:
```
It cannot start with FORGEJO_, GITEA_, GITHUB_, or a number.
```

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12213
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
Co-authored-by: zokki <zokki.softwareschmiede@gmail.com>
Co-committed-by: zokki <zokki.softwareschmiede@gmail.com>
This commit is contained in:
zokki 2026-04-21 19:55:16 +02:00 committed by Gusted
parent 529b14291d
commit 4001ab027a
2 changed files with 7 additions and 1 deletions

View file

@ -20,7 +20,7 @@ import (
var (
namePattern = regexp.MustCompile("(?i)^[A-Z_][A-Z0-9_]*$")
forbiddenPrefixPattern = regexp.MustCompile("(?i)^FORGEJO_|GITEA_|GITHUB_")
forbiddenPrefixPattern = regexp.MustCompile("(?i)^(FORGEJO_|GITEA_|GITHUB_|[0-9])")
ErrInvalidName = util.NewInvalidArgumentErrorf("invalid secret name")
)

View file

@ -257,12 +257,18 @@ func TestSecretValidateName(t *testing.T) {
valid bool
}{
{"FORGEJO_", false},
{"PRE_FORGEJO_", true},
{"PRE_FORGEJO_SUF", true},
{"FORGEJO_123", false},
{"FORGEJO_ABC", false},
{"GITEA_", false},
{"PRE_GITEA_", true},
{"PRE_GITEA_SUF", true},
{"GITEA_123", false},
{"GITEA_ABC", false},
{"GITHUB_", false},
{"PRE_GITHUB_", true},
{"PRE_GITHUB_SUF", true},
{"GITHUB_123", false},
{"GITHUB_ABC", false},
{"123_TEST", false},