Skip to content

Commit b6c1a61

Browse files
committed
sanitize for checks
1 parent 9089f12 commit b6c1a61

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

app/models/concerns/heartbeatable.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,18 @@ def duration_seconds_boundary_aware(scope, start_time, end_time)
279279
capped_diffs = combined_scope
280280
.select("time, CASE
281281
WHEN LAG(time) OVER (ORDER BY time) IS NULL THEN 0
282-
ELSE LEAST(EXTRACT(EPOCH FROM (to_timestamp(time) - to_timestamp(LAG(time) OVER (ORDER BY time)))), #{heartbeat_timeout_duration.to_i})
283-
END as diff")
282+
ELSE LEAST(EXTRACT(EPOCH FROM (to_timestamp(time) - to_timestamp(LAG(time) OVER (ORDER BY time)))), ?)
283+
END as diff", heartbeat_timeout_duration.to_i)
284284
.where.not(time: nil)
285285
.order(time: :asc)
286286

287287
connection.select_value(
288-
"SELECT COALESCE(SUM(diff), 0)::integer
289-
FROM (#{capped_diffs.to_sql}) AS diffs
290-
WHERE time >= #{start_time}"
288+
connection.sanitize_sql_array([
289+
"SELECT COALESCE(SUM(diff), 0)::integer
290+
FROM (#{capped_diffs.to_sql}) AS diffs
291+
WHERE time >= ?",
292+
start_time
293+
])
291294
).to_i
292295
end
293296
end

0 commit comments

Comments
 (0)