{"record":{"id":"6f5b3f0f50b6ac5a","repo":"FiloSottile/age","slug":"invalid-stanza-argument-q","errorCode":null,"errorMessage":"invalid stanza argument: %q","messagePattern":"invalid stanza argument: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/format/format.go","lineNumber":117,"sourceCode":"// because no input was written, or because a multiple of BytesPerLine was.\n//\n// Calling LastLineIsEmpty before Close is meaningless.\nfunc (w *WrappedBase64Encoder) LastLineIsEmpty() bool {\n\treturn w.written%ColumnsPerLine == 0\n}\n\nconst intro = \"age-encryption.org/v1\\n\"\n\nvar stanzaPrefix = []byte(\"->\")\nvar footerPrefix = []byte(\"---\")\n\nfunc (r *Stanza) Marshal(w io.Writer) error {\n\tif !isValidString(r.Type) {\n\t\treturn fmt.Errorf(\"invalid stanza type: %q\", r.Type)\n\t}\n\tfor _, a := range r.Args {\n\t\tif !isValidString(a) {\n\t\t\treturn fmt.Errorf(\"invalid stanza argument: %q\", a)\n\t\t}\n\t}\n\tif _, err := w.Write(stanzaPrefix); err != nil {\n\t\treturn err\n\t}\n\tif _, err := io.WriteString(w, \" \"+r.Type); err != nil {\n\t\treturn err\n\t}\n\tfor _, a := range r.Args {\n\t\tif _, err := io.WriteString(w, \" \"+a); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tif _, err := io.WriteString(w, \"\\n\"); err != nil {\n\t\treturn err\n\t}\n\tww := NewWrappedBase64Encoder(b64, w)\n\tif _, err := ww.Write(r.Body); err != nil {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/FiloSottile/age/blob/b74dce4cdbe35b5e5f66c06d9612b72f89028758/internal/format/format.go#L99-L135","documentation":"Same validation as the Type, applied to each element of Stanza.Args: args must be single-line printable-ASCII strings without spaces, because args are space-separated on one line of the age wire format. Marshal aborts before writing anything if an argument is invalid.","triggerScenarios":"Marshal a Stanza whose Args include a value with a space, newline, tab, or non-ASCII/control byte — e.g. base64 padded data accidentally containing '='? (= is fine) — more commonly raw binary or CRLF-terminated values passed as args.","commonSituations":"Plugin authors passing binary or multiline payloads as stanza args instead of base64-encoding them; values read from a file with trailing newline.","solutions":["Base64-encode arbitrary bytes before placing them in Args","Trim newlines/whitespace from each arg and re-check","Identify the bad arg via the %q message and fix its producer"],"exampleFix":"// before\nargs := []string{string(rawBody)}\n// after\nargs := []string{base64.RawStdEncoding.EncodeToString(rawBody)}","handlingStrategy":"validation","validationCode":"for _, a := range args {\n    for _, c := range a {\n        if c <= 32 || c > 126 { return errors.New(\"stanza arg contains invalid character\") }\n    }\n}","typeGuard":"func isArgSafe(a string) bool {\n    return a != \"\" && strings.IndexFunc(a, func(r rune) bool { return r <= 32 || r > 126 }) < 0\n}","tryCatchPattern":null,"preventionTips":["Always encode binary payloads (base64) before using them as stanza args","Trim trailing newlines from values read from files","Validate args at Stanza construction time, not just at Marshal"],"tags":["age","format","stanza","serialization"],"backgroundTag":"invalid-stanza-type","analyzedSha":"b74dce4cdbe35b5e5f66c06d9612b72f89028758","analyzedAt":"2026-08-31T23:59:31.627Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}