diff --git a/service/internal/executor/arguments.go b/service/internal/executor/arguments.go index df7770d..3b96c47 100644 --- a/service/internal/executor/arguments.go +++ b/service/internal/executor/arguments.go @@ -213,3 +213,32 @@ func typeSafetyCheckUrl(value string) error { return err } + +func mangleInvalidArgumentValues(req *ExecutionRequest) { + mangleInvalidDatetimeValues(req) +} + +func mangleInvalidDatetimeValues(req *ExecutionRequest) { + for _, arg := range req.Action.Arguments { + if arg.Type == "datetime" { + value, exists := req.Arguments[arg.Name] + + if !exists || value == "" { + continue + } + + timestamp, err := time.Parse("2006-01-02T15:04", value) + + if err == nil { + log.WithFields(log.Fields { + "arg": arg.Name, + "value": value, + "actionTitle": req.Action.Title, + }).Warnf("Mangled invalid datetime value without seconds to :00 seconds, this issue is commonly caused by Android browsers.") + + req.Arguments[arg.Name] = timestamp.Format("2006-01-02T15:04:05") + } + + } + } +} diff --git a/service/internal/executor/executor.go b/service/internal/executor/executor.go index 97ccf5e..8833992 100644 --- a/service/internal/executor/executor.go +++ b/service/internal/executor/executor.go @@ -402,6 +402,8 @@ func stepParseArgs(req *ExecutionRequest) bool { req.Arguments["ot_executionTrackingId"] = req.TrackingID req.Arguments["ot_username"] = req.AuthenticatedUser.Username + mangleInvalidArgumentValues(req) + req.finalParsedCommand, err = parseActionArguments(req.Arguments, req.Action, req.EntityPrefix) if err != nil { diff --git a/service/internal/executor/executor_test.go b/service/internal/executor/executor_test.go index 18863f1..87031ca 100644 --- a/service/internal/executor/executor_test.go +++ b/service/internal/executor/executor_test.go @@ -129,6 +129,7 @@ func TestGetLogsLessThanPageSize(t *testing.T) { Title: "blat", Shell: "date", }) + cfg.Sanitize() assert.Equal(t, int64(10), cfg.LogHistoryPageSize, "Logs page size should be 10") @@ -226,3 +227,38 @@ func TestUnusedArgumentStillPassesTypeSafetyCheck(t *testing.T) { assert.Equal(t, "", out) assert.NotNil(t, err) } + +// https://github.com/OliveTin/OliveTin/issues/564 +func TestMangleInvalidArgumentValues(t *testing.T) { + e, cfg := testingExecutor() + + a1 := &config.Action{ + Title: "Validate my date without seconds because I am from an Android phone", + Shell: "echo 'The date is: {{ date }}'", + Arguments: []config.ActionArgument{ + { + Name: "date", + Type: "datetime", + }, + }, + } + + cfg.Actions = append(cfg.Actions, a1) + cfg.Sanitize() + + req := ExecutionRequest{ + Action: a1, + AuthenticatedUser: acl.UserFromSystem(cfg, "testuser"), + Cfg: cfg, + Arguments: map[string]string{ + "date": "1990-01-10T12:00", // Invalid format, should be without seconds + }, + } + + wg, _ := e.ExecRequest(&req) + wg.Wait() + + assert.NotNil(t, req.logEntry, "Log entry should not be nil") + assert.Equal(t, req.logEntry.Output, "The date is: 1990-01-10T12:00:00\n", "Date should be mangled to a valid format") + +}