isLocalFileForUpdate returns true when importPath resolves to an existing file within localWorkflowDir. The resolved absolute path must stay inside localWorkflowDir to guard against path traversal (e.g. "../../etc/passwd" in import paths). importPath must be a relative path — callers must not pass a
(localWorkflowDir, importPath string)
| 380 | // to guard against path traversal (e.g. "../../etc/passwd" in import paths). |
| 381 | // importPath must be a relative path — callers must not pass absolute paths here. |
| 382 | func isLocalFileForUpdate(localWorkflowDir, importPath string) bool { |
| 383 | if localWorkflowDir == "" || importPath == "" { |
| 384 | return false |
| 385 | } |
| 386 | localPath := filepath.Join(localWorkflowDir, importPath) |
| 387 | absDir, err1 := filepath.Abs(localWorkflowDir) |
| 388 | absPath, err2 := filepath.Abs(localPath) |
| 389 | if err1 != nil || err2 != nil { |
| 390 | return false |
| 391 | } |
| 392 | // Reject traversal attempts: the resolved path must be a child of localWorkflowDir |
| 393 | if !strings.HasPrefix(absPath, absDir+string(filepath.Separator)) { |
| 394 | return false |
| 395 | } |
| 396 | _, statErr := os.Stat(localPath) |
| 397 | return statErr == nil |
| 398 | } |
| 399 | |
| 400 | // isWorkflowSpecFormat reports whether path is a workflowspec-style reference. |
| 401 | // It delegates to parser.IsWorkflowSpec to keep CLI and parser behavior consistent. |
no outgoing calls