@@ -308,6 +308,7 @@ func (api *API) insightsTemplates(rw http.ResponseWriter, r *http.Request) {
308
308
// to provide the hour of the day (e.g. 14:00:00).
309
309
func parseInsightsStartAndEndTime (ctx context.Context ,rw http.ResponseWriter ,startTimeString ,endTimeString string ) (startTime ,endTime time.Time ,ok bool ) {
310
310
const insightsTimeLayout = time .RFC3339Nano
311
+ now := time .Now ()
311
312
312
313
for _ ,qp := range []struct {
313
314
name ,value string
@@ -329,6 +330,7 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
329
330
})
330
331
return time.Time {}, time.Time {},false
331
332
}
333
+
332
334
if t .IsZero () {
333
335
httpapi .Write (ctx ,rw ,http .StatusBadRequest , codersdk.Response {
334
336
Message :"Query parameter has invalid value." ,
@@ -341,10 +343,24 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
341
343
})
342
344
return time.Time {}, time.Time {},false
343
345
}
346
+
347
+ if t .After (now ) {
348
+ httpapi .Write (ctx ,rw ,http .StatusBadRequest , codersdk.Response {
349
+ Message :"Query parameter has invalid value." ,
350
+ Validations : []codersdk.ValidationError {
351
+ {
352
+ Field :qp .name ,
353
+ Detail :fmt .Sprintf ("Query param %q must not be in the future" ,qp .name ),
354
+ },
355
+ },
356
+ })
357
+ return time.Time {}, time.Time {},false
358
+ }
359
+
344
360
ensureZeroHour := true
345
361
if qp .name == "end_time" {
346
362
ey ,em ,ed := t .Date ()
347
- ty ,tm ,td := time . Now () .Date ()
363
+ ty ,tm ,td := now .Date ()
348
364
349
365
ensureZeroHour = ey != ty || em != tm || ed != td
350
366
}