Files
ask-form/skill/security_test.go
gabrielvidal aecb37086d security(cli,ci,docs): default auto-upgrade to notify, harden installer/CLI/skills and pin CI actions
- Change default ASK_FORM_AUTO_UPGRADE to notify, enforce HTTPS/no-downgrade redirects,
  block pre-release auto-installs, and run smoke tests with an empty environment
- Validate browser URLs (http/https only) and relay URLs, write secrets atomically at 0600,
  add --token-file/--key-file, and harden systemd/launchd unit generation
- Enforce TLS 1.2 + strict semver tag validation in install.sh and npm publish scripts
- Validate and quote origins/keys in Claude.ai and MCP plugin zips
- Pin GitHub Actions to commit SHAs, scope job permissions, and document relay trust boundaries
2026-11-23 11:32:50 +01:00

68 lines
1.5 KiB
Go

package skill
import (
"archive/zip"
"bytes"
"encoding/json"
"io"
"testing"
askform "github.com/GabrielVidal1/ask-form"
)
func TestClaudeAIZipRejectsInjection(t *testing.T) {
badRelays := []string{
"http://ask-form.xyz",
"https://ask-form.xyz';id;'",
"https://ask-form.xyz/path",
"javascript:alert(1)",
}
for _, r := range badRelays {
if _, err := ClaudeAIZip(r, "afk_validkey123", "v1.0.0"); err == nil {
t.Errorf("expected invalid relay %q to be rejected", r)
}
}
badKeys := []string{
"",
"afk_bad'$(id)",
"afk_bad\nnewline",
"afk_bad space",
}
for _, k := range badKeys {
if _, err := ClaudeAIZip("https://ask-form.xyz", k, "v1.0.0"); err == nil {
t.Errorf("expected invalid key %q to be rejected", k)
}
}
}
func TestPluginZipRejectsBadOriginAndProducesValidJSON(t *testing.T) {
for _, bad := range []string{
"http://evil.example",
`https://evil.example","injected":"x`,
"javascript:alert(1)",
} {
if _, err := PluginZip(askform.Plugin, bad); err == nil {
t.Errorf("expected invalid origin %q to be rejected", bad)
}
}
b, err := PluginZip(askform.Plugin, "https://forms.example.com/")
if err != nil {
t.Fatal(err)
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
t.Fatal(err)
}
for _, f := range zr.File {
if f.Name == "ask-form/.mcp.json" || f.Name == "ask-form/mcp.json" {
rc, _ := f.Open()
raw, _ := io.ReadAll(rc)
rc.Close()
var m map[string]any
if err := json.Unmarshal(raw, &m); err != nil {
t.Errorf("%s invalid JSON: %v", f.Name, err)
}
}
}
}