chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package cmdutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ValidateProfileName enforces the profile-name allowlist: letters, digits,
|
||||
// dash, underscore, dot. The `.` exception lets email / DNS-like names
|
||||
// through; `.` / `..` and path separators are structurally rejected so a
|
||||
// hand-edited config.yaml can't claim a profile whose name walks out of the
|
||||
// keyring namespace.
|
||||
//
|
||||
// Crucially this also rejects shell metacharacters (space, `;`, `&`, `|`,
|
||||
// `$`, quotes, backticks, etc.), so the profile name remains safe to embed
|
||||
// in envelope.error.retry_argv — even an agent that joins the argv and exec's
|
||||
// `sh -c <joined>` cannot be tricked via a maliciously-named profile.
|
||||
func ValidateProfileName(name string) error {
|
||||
if name == "" {
|
||||
return &Error{
|
||||
Code: CodeInputInvalidArgument,
|
||||
Message: "profile name must not be empty",
|
||||
}
|
||||
}
|
||||
if name == "." || name == ".." || strings.Contains(name, "/") || strings.Contains(name, "\\") {
|
||||
return &Error{
|
||||
Code: CodeInputInvalidArgument,
|
||||
Message: fmt.Sprintf("profile name %q is reserved or path-like", name),
|
||||
Hint: "use letters, digits, dashes, underscores, or dots",
|
||||
}
|
||||
}
|
||||
for _, r := range name {
|
||||
switch {
|
||||
case r >= 'a' && r <= 'z',
|
||||
r >= 'A' && r <= 'Z',
|
||||
r >= '0' && r <= '9',
|
||||
r == '-' || r == '_' || r == '.':
|
||||
continue
|
||||
default:
|
||||
return &Error{
|
||||
Code: CodeInputInvalidArgument,
|
||||
Message: fmt.Sprintf("profile name %q contains invalid character %q", name, r),
|
||||
Hint: "use letters, digits, dashes, underscores, or dots",
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user