add: fail fast on invalid attachment entries
This commit is contained in:
parent
6d4d2ed7a0
commit
cd842e265e
1 changed files with 9 additions and 5 deletions
|
|
@ -115,21 +115,25 @@ func (t *MessageTool) Execute(ctx context.Context, args map[string]interface{})
|
||||||
// Parse attachments if provided
|
// Parse attachments if provided
|
||||||
var attachments []bus.Attachment
|
var attachments []bus.Attachment
|
||||||
if attachmentsRaw, ok := args["attachments"].([]interface{}); ok {
|
if attachmentsRaw, ok := args["attachments"].([]interface{}); ok {
|
||||||
for _, attachRaw := range attachmentsRaw {
|
for i, attachRaw := range attachmentsRaw {
|
||||||
attachMap, ok := attachRaw.(map[string]interface{})
|
attachMap, ok := attachRaw.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
continue // Skip invalid attachment entries
|
return ErrorResult(fmt.Sprintf("attachments[%d]: expected an object, got %T", i, attachRaw))
|
||||||
}
|
}
|
||||||
|
|
||||||
path, pathOk := attachMap["path"].(string)
|
path, pathOk := attachMap["path"].(string)
|
||||||
|
if !pathOk || path == "" {
|
||||||
|
return ErrorResult(fmt.Sprintf("attachments[%d]: missing or invalid \"path\" field", i))
|
||||||
|
}
|
||||||
|
|
||||||
filename, filenameOk := attachMap["filename"].(string)
|
filename, filenameOk := attachMap["filename"].(string)
|
||||||
if !pathOk || !filenameOk {
|
if !filenameOk || filename == "" {
|
||||||
continue // Skip invalid attachment entries
|
return ErrorResult(fmt.Sprintf("attachments[%d]: missing or invalid \"filename\" field", i))
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvedPath, err := validatePath(path, t.allowedDir, t.restrict)
|
resolvedPath, err := validatePath(path, t.allowedDir, t.restrict)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrorResult(err.Error())
|
return ErrorResult(fmt.Sprintf("attachments[%d]: %v", i, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
attachments = append(attachments, bus.Attachment{
|
attachments = append(attachments, bus.Attachment{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue