Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2198c5f

Browse files
committed
prevent timetravel
1 parent6326643 commit2198c5f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎coderd/insights.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func (api *API) insightsTemplates(rw http.ResponseWriter, r *http.Request) {
308308
// to provide the hour of the day (e.g. 14:00:00).
309309
funcparseInsightsStartAndEndTime(ctx context.Context,rw http.ResponseWriter,startTimeString,endTimeStringstring) (startTime,endTime time.Time,okbool) {
310310
constinsightsTimeLayout=time.RFC3339Nano
311+
now:=time.Now()
311312

312313
for_,qp:=range []struct {
313314
name,valuestring
@@ -329,6 +330,7 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
329330
})
330331
return time.Time{}, time.Time{},false
331332
}
333+
332334
ift.IsZero() {
333335
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
334336
Message:"Query parameter has invalid value.",
@@ -341,10 +343,24 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
341343
})
342344
return time.Time{}, time.Time{},false
343345
}
346+
347+
ift.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+
344360
ensureZeroHour:=true
345361
ifqp.name=="end_time" {
346362
ey,em,ed:=t.Date()
347-
ty,tm,td:=time.Now().Date()
363+
ty,tm,td:=now.Date()
348364

349365
ensureZeroHour=ey!=ty||em!=tm||ed!=td
350366
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp