Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps] [Alerting] Handle invalid RRule params and prevent infinite looping #205650

Merged
merged 12 commits into from
Jan 7, 2025

Conversation

Zacqary
Copy link
Contributor

@Zacqary Zacqary commented Jan 6, 2025

Summary

Closes #205558

Updates the RRule library to correctly handle some scenarios with invalid parameters that would either cause it to return strange recurrence data or to infinitely loop. Specifically:

  • On RRule object creation, removes and ignores any bymonth, bymonthday, byweekday, or byyearday value that's out of bounds, e.g. less than 0 or greater than the number of possible months, days, weekdays, etc.
  • Successfully ignores cases of BYMONTH=2, BYMONTHDAY=30 (February 30th), an input that's complicated to invalidate but still won't ever occur

Allowing these values to go unhandled led to unpredictable behavior. The RRule library uses Moment.js to compare dates, but Moment.js months, days, and other values generally start at 0 while RRule values start at 1. That led to several circumstances where we passed Moment.js a value of -1, which Moment.js interpreted as moving to the previous year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library was constantly iterating through the wrong year, never reaching the date it was supposed to end on.

In addition to making the RRule library more able to handle these cases, this PR also gives it a hard 100,000 iteration limit to prevent any possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to hopefully prevent out of bounds dates from ever being set.

Checklist

@Zacqary Zacqary added release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v9.0.0 Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework v8.18.0 labels Jan 6, 2025
@Zacqary Zacqary requested a review from a team as a code owner January 6, 2025 19:50
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@Zacqary Zacqary added the backport:version Backport to applied version labels label Jan 6, 2025
@@ -345,7 +306,7 @@ const getMonthOfRecurrences = function ({
}: IterOptions) {
const derivedByweekday = byweekday ?? ISO_WEEKDAYS;
const currentMonth = refDT.month();
if (bymonth && !bymonth.includes(currentMonth)) return [];
if (bymonth && !bymonth.includes(currentMonth + 1)) return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change about? I can't understand what getMonthOfRecurrences does

Copy link
Contributor Author

@Zacqary Zacqary Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change handles the difference between bymonth starting January at 1 and Moment.js starting January at 0. currentMonth is a Moment.js month, so we need to add 1 to it to accurately check if it matches bymonth.

getMonthOfRecurrences iterates over the month specified by refDT (a Moment object) to find all recurrences within that month. For example, if we pass Jan 7 2025 10:00:00, it will iterate over all of January 2025.

This is used for recurrences that happen at a monthly frequency or a yearly frequency.

This function previously wasn't being called with a bymonth parameter very often (yearly frequency was using a method to omit bymonth, which was a misguided approach that caused some infinite looping issues), so we never caught this bug.

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and validation works as expected.

@@ -112,12 +66,17 @@ export class RRule {
.toDate();

const nextRecurrences: Moment[] = [];
let iters = 0;

while (
(!count && !until) ||
(count && yieldedRecurrenceCount < count) ||
(until && current.getTime() < new Date(until).getTime())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If until is already type Date why are we doing new Date(until).getTime()?

This is probably by mistake but at least it doesn't throw.

> const until = new Date('February 25, 2022 03:24:00')
undefined
> until
2022-02-25T02:24:00.000Z
> const foobar = new Date(until)
undefined
> foobar
2022-02-25T02:24:00.000Z
> foobar.getTime()
1645755840000
> until.getTime()
1645755840000

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, until is already a sanitized date, so it is safe to use until.getTime()

@adcoelho adcoelho force-pushed the 205558-rrule-invalid-fix branch from 91be1b6 to d3662ea Compare January 7, 2025 15:29
@ymao1 ymao1 added the v8.17.0 label Jan 7, 2025
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
alerting 223 225 +2

History

@@ -74,19 +32,15 @@ type AllResult = Date[] & {
};

const ALL_LIMIT = 10000;
const TIMEOUT_LIMIT = 100000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a drive-by comment wondering if we really need to let it run 100,000 iterations before hard-exiting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with this stuff at all but seems like if we could lower this and have it exit earlier, would be better. But if we need up to 100,000 iterations, then you can disregard :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default limit on getting "all" recurrences of a schedule that has no end is 10k, we want to give it enough of a buffer that it might actually be able to find 10k recurrences.

Kibana isn't really hitting those limits right now but since 100k iterations takes a negligible amount of compute time to do, it seems like a decent ceiling to future-proof this.

@Zacqary Zacqary merged commit b302109 into elastic:main Jan 7, 2025
15 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.17, 8.x

https://github.com/elastic/kibana/actions/runs/12658052124

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 7, 2025
…nite looping (elastic#205650)

## Summary

Closes elastic#205558

Updates the RRule library to correctly handle some scenarios with
invalid parameters that would either cause it to return strange
recurrence data or to infinitely loop. Specifically:

- On `RRule` object creation, removes and ignores any `bymonth`,
`bymonthday`, `byweekday`, or `byyearday` value that's out of bounds,
e.g. less than 0 or greater than the number of possible months, days,
weekdays, etc.
- Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30` (February
30th), an input that's complicated to invalidate but still won't ever
occur

Allowing these values to go unhandled led to unpredictable behavior. The
RRule library uses Moment.js to compare dates, but Moment.js months,
days, and other values generally start at `0` while RRule values start
at `1`. That led to several circumstances where we passed Moment.js a
value of `-1`, which Moment.js interpreted as moving to the
***previous*** year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library
was constantly iterating through the wrong year, never reaching the date
it was supposed to end on.

In addition to making the RRule library more able to handle these cases,
this PR also gives it a hard 100,000 iteration limit to prevent any
possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to
hopefully prevent out of bounds dates from ever being set.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: adcoelho <[email protected]>
(cherry picked from commit b302109)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.16 Backport failed because of merge conflicts
8.17 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.17:
- [AVC Banner] Updates the AVC Banner for 2025 (#205467)
- [Security Solution] Fix timeline dynamic batching (#204034)
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 205650

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 7, 2025
…t infinite looping (#205650) (#205803)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps] [Alerting] Handle invalid RRule params and prevent
infinite looping
(#205650)](#205650)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Zacqary Adam
Xeper","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-07T19:32:43Z","message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesFramework","backport:version","v8.18.0","v8.16.3","v8.17.1"],"title":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite
looping","number":205650,"url":"https://github.com/elastic/kibana/pull/205650","mergeCommit":{"message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205650","number":205650,"mergeCommit":{"message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Zacqary Adam Xeper <[email protected]>
kowalczyk-krzysztof pushed a commit to kowalczyk-krzysztof/kibana that referenced this pull request Jan 7, 2025
…nite looping (elastic#205650)

## Summary

Closes elastic#205558

Updates the RRule library to correctly handle some scenarios with
invalid parameters that would either cause it to return strange
recurrence data or to infinitely loop. Specifically:

- On `RRule` object creation, removes and ignores any `bymonth`,
`bymonthday`, `byweekday`, or `byyearday` value that's out of bounds,
e.g. less than 0 or greater than the number of possible months, days,
weekdays, etc.
- Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30` (February
30th), an input that's complicated to invalidate but still won't ever
occur

Allowing these values to go unhandled led to unpredictable behavior. The
RRule library uses Moment.js to compare dates, but Moment.js months,
days, and other values generally start at `0` while RRule values start
at `1`. That led to several circumstances where we passed Moment.js a
value of `-1`, which Moment.js interpreted as moving to the
***previous*** year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library
was constantly iterating through the wrong year, never reaching the date
it was supposed to end on.

In addition to making the RRule library more able to handle these cases,
this PR also gives it a hard 100,000 iteration limit to prevent any
possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to
hopefully prevent out of bounds dates from ever being set.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: adcoelho <[email protected]>
mikecote pushed a commit to mikecote/kibana that referenced this pull request Jan 8, 2025
…nite looping (elastic#205650)

## Summary

Closes elastic#205558

Updates the RRule library to correctly handle some scenarios with
invalid parameters that would either cause it to return strange
recurrence data or to infinitely loop. Specifically:

- On `RRule` object creation, removes and ignores any `bymonth`,
`bymonthday`, `byweekday`, or `byyearday` value that's out of bounds,
e.g. less than 0 or greater than the number of possible months, days,
weekdays, etc.
- Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30` (February
30th), an input that's complicated to invalidate but still won't ever
occur

Allowing these values to go unhandled led to unpredictable behavior. The
RRule library uses Moment.js to compare dates, but Moment.js months,
days, and other values generally start at `0` while RRule values start
at `1`. That led to several circumstances where we passed Moment.js a
value of `-1`, which Moment.js interpreted as moving to the
***previous*** year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library
was constantly iterating through the wrong year, never reaching the date
it was supposed to end on.

In addition to making the RRule library more able to handle these cases,
this PR also gives it a hard 100,000 iteration limit to prevent any
possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to
hopefully prevent out of bounds dates from ever being set.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: adcoelho <[email protected]>
(cherry picked from commit b302109)

# Conflicts:
#	packages/kbn-rrule/sanitize.test.ts
#	packages/kbn-rrule/sanitize.ts
#	packages/kbn-rrule/types.ts
@mikecote
Copy link
Contributor

mikecote commented Jan 8, 2025

💚 All backports created successfully

Status Branch Result
8.17
8.16

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

mikecote pushed a commit to mikecote/kibana that referenced this pull request Jan 8, 2025
…nite looping (elastic#205650)

## Summary

Closes elastic#205558

Updates the RRule library to correctly handle some scenarios with
invalid parameters that would either cause it to return strange
recurrence data or to infinitely loop. Specifically:

- On `RRule` object creation, removes and ignores any `bymonth`,
`bymonthday`, `byweekday`, or `byyearday` value that's out of bounds,
e.g. less than 0 or greater than the number of possible months, days,
weekdays, etc.
- Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30` (February
30th), an input that's complicated to invalidate but still won't ever
occur

Allowing these values to go unhandled led to unpredictable behavior. The
RRule library uses Moment.js to compare dates, but Moment.js months,
days, and other values generally start at `0` while RRule values start
at `1`. That led to several circumstances where we passed Moment.js a
value of `-1`, which Moment.js interpreted as moving to the
***previous*** year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library
was constantly iterating through the wrong year, never reaching the date
it was supposed to end on.

In addition to making the RRule library more able to handle these cases,
this PR also gives it a hard 100,000 iteration limit to prevent any
possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to
hopefully prevent out of bounds dates from ever being set.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: adcoelho <[email protected]>
(cherry picked from commit b302109)

# Conflicts:
#	packages/kbn-rrule/rrule.ts
#	packages/kbn-rrule/sanitize.test.ts
#	packages/kbn-rrule/sanitize.ts
#	packages/kbn-rrule/types.ts
mikecote added a commit that referenced this pull request Jan 8, 2025
…nt infinite looping (#205650) (#205830)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[ResponseOps] [Alerting] Handle invalid RRule params and prevent
infinite looping
(#205650)](#205650)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Zacqary Adam
Xeper","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-07T19:32:43Z","message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesFramework","backport:version","v8.18.0","v8.16.3","v8.17.1"],"number":205650,"url":"https://github.com/elastic/kibana/pull/205650","mergeCommit":{"message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205650","number":205650,"mergeCommit":{"message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/205803","number":205803,"state":"MERGED","mergeCommit":{"sha":"a02fcb232faed2f385ce9b97fbdb323ccbf8ca45","message":"[8.x]
[ResponseOps] [Alerting] Handle invalid RRule params and prevent
infinite looping (#205650) (#205803)\n\n# Backport\n\nThis will backport
the following commits from `main` to `8.x`:\n- [[ResponseOps] [Alerting]
Handle invalid RRule params and prevent\ninfinite
looping\n(#205650)](https://github.com/elastic/kibana/pull/205650)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Zacqary
Adam\nXeper\",\"email\":\"[email protected]\"},\"sourceCommit\":{\"committedDate\":\"2025-01-07T19:32:43Z\",\"message\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent infinite
looping\n(#205650)\\n\\n##
Summary\\r\\n\\r\\nCloses\nhttps://github.com//issues/205558\\r\\n\\r\\nUpdates
the RRule\nlibrary to correctly handle some scenarios with\\r\\ninvalid
parameters\nthat would either cause it to return strange\\r\\nrecurrence
data or to\ninfinitely loop. Specifically:\\r\\n\\r\\n- On `RRule`
object creation,\nremoves and ignores any `bymonth`,\\r\\n`bymonthday`,
`byweekday`, or\n`byyearday` value that's out of bounds,\\r\\ne.g. less
than 0 or greater\nthan the number of possible months,
days,\\r\\nweekdays, etc.\\r\\n-\nSuccessfully ignores cases of
`BYMONTH=2, BYMONTHDAY=30`\n(February\\r\\n30th), an input that's
complicated to invalidate but still\nwon't
ever\\r\\noccur\\r\\n\\r\\nAllowing these values to go unhandled led
to\nunpredictable behavior. The\\r\\nRRule library uses Moment.js to
compare\ndates, but Moment.js months,\\r\\ndays, and other values
generally start\nat `0` while RRule values start\\r\\nat `1`. That led
to several\ncircumstances where we passed Moment.js a\\r\\nvalue of
`-1`, which\nMoment.js interpreted as moving to the\\r\\n***previous***
year, month, or\nother period of time.\\r\\n\\r\\nAt worst, this could
cause an infinite loop\nbecause the RRule library\\r\\nwas constantly
iterating through the wrong\nyear, never reaching the date\\r\\nit was
supposed to end on.\\r\\n\\r\\nIn\naddition to making the RRule library
more able to handle these\ncases,\\r\\nthis PR also gives it a hard
100,000 iteration limit to\nprevent any\\r\\npossible infinite loops
we've missed.\\r\\n\\r\\nLastly, the\nSnooze Schedule APIs also come
with additional validation\nto\\r\\nhopefully prevent out of bounds
dates from ever being\nset.\\r\\n\\r\\n### Checklist\\r\\n\\r\\n- [x]
[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\\r\\n\\r\\n---------\\r\\n\\r\\nCo-authored-by:
kibanamachine\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi <[email protected]>\\r\\nCo-authored-by:
adcoelho\n<[email protected]>\",\"sha\":\"b30210929be0824f684f0b7d9d13bc936c1cbd22\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.18.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:fix\",\"Team:ResponseOps\",\"v9.0.0\",\"Feature:Alerting/RulesFramework\",\"backport:version\",\"v8.18.0\",\"v8.16.3\",\"v8.17.1\"],\"title\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent
infinite\nlooping\",\"number\":205650,\"url\":\"https://github.com/elastic/kibana/pull/205650\",\"mergeCommit\":{\"message\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent infinite
looping\n(#205650)\\n\\n##
Summary\\r\\n\\r\\nCloses\nhttps://github.com//issues/205558\\r\\n\\r\\nUpdates
the RRule\nlibrary to correctly handle some scenarios with\\r\\ninvalid
parameters\nthat would either cause it to return strange\\r\\nrecurrence
data or to\ninfinitely loop. Specifically:\\r\\n\\r\\n- On `RRule`
object creation,\nremoves and ignores any `bymonth`,\\r\\n`bymonthday`,
`byweekday`, or\n`byyearday` value that's out of bounds,\\r\\ne.g. less
than 0 or greater\nthan the number of possible months,
days,\\r\\nweekdays, etc.\\r\\n-\nSuccessfully ignores cases of
`BYMONTH=2, BYMONTHDAY=30`\n(February\\r\\n30th), an input that's
complicated to invalidate but still\nwon't
ever\\r\\noccur\\r\\n\\r\\nAllowing these values to go unhandled led
to\nunpredictable behavior. The\\r\\nRRule library uses Moment.js to
compare\ndates, but Moment.js months,\\r\\ndays, and other values
generally start\nat `0` while RRule values start\\r\\nat `1`. That led
to several\ncircumstances where we passed Moment.js a\\r\\nvalue of
`-1`, which\nMoment.js interpreted as moving to the\\r\\n***previous***
year, month, or\nother period of time.\\r\\n\\r\\nAt worst, this could
cause an infinite loop\nbecause the RRule library\\r\\nwas constantly
iterating through the wrong\nyear, never reaching the date\\r\\nit was
supposed to end on.\\r\\n\\r\\nIn\naddition to making the RRule library
more able to handle these\ncases,\\r\\nthis PR also gives it a hard
100,000 iteration limit to\nprevent any\\r\\npossible infinite loops
we've missed.\\r\\n\\r\\nLastly, the\nSnooze Schedule APIs also come
with additional validation\nto\\r\\nhopefully prevent out of bounds
dates from ever being\nset.\\r\\n\\r\\n### Checklist\\r\\n\\r\\n- [x]
[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\\r\\n\\r\\n---------\\r\\n\\r\\nCo-authored-by:
kibanamachine\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi <[email protected]>\\r\\nCo-authored-by:
adcoelho\n<[email protected]>\",\"sha\":\"b30210929be0824f684f0b7d9d13bc936c1cbd22\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.x\",\"8.16\",\"8.17\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/205650\",\"number\":205650,\"mergeCommit\":{\"message\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent infinite
looping\n(#205650)\\n\\n##
Summary\\r\\n\\r\\nCloses\nhttps://github.com//issues/205558\\r\\n\\r\\nUpdates
the RRule\nlibrary to correctly handle some scenarios with\\r\\ninvalid
parameters\nthat would either cause it to return strange\\r\\nrecurrence
data or to\ninfinitely loop. Specifically:\\r\\n\\r\\n- On `RRule`
object creation,\nremoves and ignores any `bymonth`,\\r\\n`bymonthday`,
`byweekday`, or\n`byyearday` value that's out of bounds,\\r\\ne.g. less
than 0 or greater\nthan the number of possible months,
days,\\r\\nweekdays, etc.\\r\\n-\nSuccessfully ignores cases of
`BYMONTH=2, BYMONTHDAY=30`\n(February\\r\\n30th), an input that's
complicated to invalidate but still\nwon't
ever\\r\\noccur\\r\\n\\r\\nAllowing these values to go unhandled led
to\nunpredictable behavior. The\\r\\nRRule library uses Moment.js to
compare\ndates, but Moment.js months,\\r\\ndays, and other values
generally start\nat `0` while RRule values start\\r\\nat `1`. That led
to several\ncircumstances where we passed Moment.js a\\r\\nvalue of
`-1`, which\nMoment.js interpreted as moving to the\\r\\n***previous***
year, month, or\nother period of time.\\r\\n\\r\\nAt worst, this could
cause an infinite loop\nbecause the RRule library\\r\\nwas constantly
iterating through the wrong\nyear, never reaching the date\\r\\nit was
supposed to end on.\\r\\n\\r\\nIn\naddition to making the RRule library
more able to handle these\ncases,\\r\\nthis PR also gives it a hard
100,000 iteration limit to\nprevent any\\r\\npossible infinite loops
we've missed.\\r\\n\\r\\nLastly, the\nSnooze Schedule APIs also come
with additional validation\nto\\r\\nhopefully prevent out of bounds
dates from ever being\nset.\\r\\n\\r\\n### Checklist\\r\\n\\r\\n- [x]
[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\\r\\n\\r\\n---------\\r\\n\\r\\nCo-authored-by:
kibanamachine\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi <[email protected]>\\r\\nCo-authored-by:
adcoelho\n<[email protected]>\",\"sha\":\"b30210929be0824f684f0b7d9d13bc936c1cbd22\"}},{\"branch\":\"8.x\",\"label\":\"v8.18.0\",\"branchLabelMappingKey\":\"^v8.18.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"8.16\",\"label\":\"v8.16.3\",\"branchLabelMappingKey\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"8.17\",\"label\":\"v8.17.1\",\"branchLabelMappingKey\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Zacqary Adam Xeper
<[email protected]>"}},{"branch":"8.16","label":"v8.16.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Zacqary Adam Xeper <[email protected]>
mikecote added a commit that referenced this pull request Jan 8, 2025
…nt infinite looping (#205650) (#205831)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[ResponseOps] [Alerting] Handle invalid RRule params and prevent
infinite looping
(#205650)](#205650)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Zacqary Adam
Xeper","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-07T19:32:43Z","message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","Feature:Alerting/RulesFramework","backport:version","v8.18.0","v8.16.3","v8.17.1"],"number":205650,"url":"https://github.com/elastic/kibana/pull/205650","mergeCommit":{"message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205650","number":205650,"mergeCommit":{"message":"[ResponseOps]
[Alerting] Handle invalid RRule params and prevent infinite looping
(#205650)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/205558\r\n\r\nUpdates the RRule
library to correctly handle some scenarios with\r\ninvalid parameters
that would either cause it to return strange\r\nrecurrence data or to
infinitely loop. Specifically:\r\n\r\n- On `RRule` object creation,
removes and ignores any `bymonth`,\r\n`bymonthday`, `byweekday`, or
`byyearday` value that's out of bounds,\r\ne.g. less than 0 or greater
than the number of possible months, days,\r\nweekdays, etc.\r\n-
Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30`
(February\r\n30th), an input that's complicated to invalidate but still
won't ever\r\noccur\r\n\r\nAllowing these values to go unhandled led to
unpredictable behavior. The\r\nRRule library uses Moment.js to compare
dates, but Moment.js months,\r\ndays, and other values generally start
at `0` while RRule values start\r\nat `1`. That led to several
circumstances where we passed Moment.js a\r\nvalue of `-1`, which
Moment.js interpreted as moving to the\r\n***previous*** year, month, or
other period of time.\r\n\r\nAt worst, this could cause an infinite loop
because the RRule library\r\nwas constantly iterating through the wrong
year, never reaching the date\r\nit was supposed to end on.\r\n\r\nIn
addition to making the RRule library more able to handle these
cases,\r\nthis PR also gives it a hard 100,000 iteration limit to
prevent any\r\npossible infinite loops we've missed.\r\n\r\nLastly, the
Snooze Schedule APIs also come with additional validation
to\r\nhopefully prevent out of bounds dates from ever being
set.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Janki Salvi
<[email protected]>\r\nCo-authored-by:
Janki Salvi <[email protected]>\r\nCo-authored-by: adcoelho
<[email protected]>","sha":"b30210929be0824f684f0b7d9d13bc936c1cbd22"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/205803","number":205803,"state":"MERGED","mergeCommit":{"sha":"a02fcb232faed2f385ce9b97fbdb323ccbf8ca45","message":"[8.x]
[ResponseOps] [Alerting] Handle invalid RRule params and prevent
infinite looping (#205650) (#205803)\n\n# Backport\n\nThis will backport
the following commits from `main` to `8.x`:\n- [[ResponseOps] [Alerting]
Handle invalid RRule params and prevent\ninfinite
looping\n(#205650)](https://github.com/elastic/kibana/pull/205650)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Zacqary
Adam\nXeper\",\"email\":\"[email protected]\"},\"sourceCommit\":{\"committedDate\":\"2025-01-07T19:32:43Z\",\"message\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent infinite
looping\n(#205650)\\n\\n##
Summary\\r\\n\\r\\nCloses\nhttps://github.com//issues/205558\\r\\n\\r\\nUpdates
the RRule\nlibrary to correctly handle some scenarios with\\r\\ninvalid
parameters\nthat would either cause it to return strange\\r\\nrecurrence
data or to\ninfinitely loop. Specifically:\\r\\n\\r\\n- On `RRule`
object creation,\nremoves and ignores any `bymonth`,\\r\\n`bymonthday`,
`byweekday`, or\n`byyearday` value that's out of bounds,\\r\\ne.g. less
than 0 or greater\nthan the number of possible months,
days,\\r\\nweekdays, etc.\\r\\n-\nSuccessfully ignores cases of
`BYMONTH=2, BYMONTHDAY=30`\n(February\\r\\n30th), an input that's
complicated to invalidate but still\nwon't
ever\\r\\noccur\\r\\n\\r\\nAllowing these values to go unhandled led
to\nunpredictable behavior. The\\r\\nRRule library uses Moment.js to
compare\ndates, but Moment.js months,\\r\\ndays, and other values
generally start\nat `0` while RRule values start\\r\\nat `1`. That led
to several\ncircumstances where we passed Moment.js a\\r\\nvalue of
`-1`, which\nMoment.js interpreted as moving to the\\r\\n***previous***
year, month, or\nother period of time.\\r\\n\\r\\nAt worst, this could
cause an infinite loop\nbecause the RRule library\\r\\nwas constantly
iterating through the wrong\nyear, never reaching the date\\r\\nit was
supposed to end on.\\r\\n\\r\\nIn\naddition to making the RRule library
more able to handle these\ncases,\\r\\nthis PR also gives it a hard
100,000 iteration limit to\nprevent any\\r\\npossible infinite loops
we've missed.\\r\\n\\r\\nLastly, the\nSnooze Schedule APIs also come
with additional validation\nto\\r\\nhopefully prevent out of bounds
dates from ever being\nset.\\r\\n\\r\\n### Checklist\\r\\n\\r\\n- [x]
[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\\r\\n\\r\\n---------\\r\\n\\r\\nCo-authored-by:
kibanamachine\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi <[email protected]>\\r\\nCo-authored-by:
adcoelho\n<[email protected]>\",\"sha\":\"b30210929be0824f684f0b7d9d13bc936c1cbd22\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.18.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:fix\",\"Team:ResponseOps\",\"v9.0.0\",\"Feature:Alerting/RulesFramework\",\"backport:version\",\"v8.18.0\",\"v8.16.3\",\"v8.17.1\"],\"title\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent
infinite\nlooping\",\"number\":205650,\"url\":\"https://github.com/elastic/kibana/pull/205650\",\"mergeCommit\":{\"message\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent infinite
looping\n(#205650)\\n\\n##
Summary\\r\\n\\r\\nCloses\nhttps://github.com//issues/205558\\r\\n\\r\\nUpdates
the RRule\nlibrary to correctly handle some scenarios with\\r\\ninvalid
parameters\nthat would either cause it to return strange\\r\\nrecurrence
data or to\ninfinitely loop. Specifically:\\r\\n\\r\\n- On `RRule`
object creation,\nremoves and ignores any `bymonth`,\\r\\n`bymonthday`,
`byweekday`, or\n`byyearday` value that's out of bounds,\\r\\ne.g. less
than 0 or greater\nthan the number of possible months,
days,\\r\\nweekdays, etc.\\r\\n-\nSuccessfully ignores cases of
`BYMONTH=2, BYMONTHDAY=30`\n(February\\r\\n30th), an input that's
complicated to invalidate but still\nwon't
ever\\r\\noccur\\r\\n\\r\\nAllowing these values to go unhandled led
to\nunpredictable behavior. The\\r\\nRRule library uses Moment.js to
compare\ndates, but Moment.js months,\\r\\ndays, and other values
generally start\nat `0` while RRule values start\\r\\nat `1`. That led
to several\ncircumstances where we passed Moment.js a\\r\\nvalue of
`-1`, which\nMoment.js interpreted as moving to the\\r\\n***previous***
year, month, or\nother period of time.\\r\\n\\r\\nAt worst, this could
cause an infinite loop\nbecause the RRule library\\r\\nwas constantly
iterating through the wrong\nyear, never reaching the date\\r\\nit was
supposed to end on.\\r\\n\\r\\nIn\naddition to making the RRule library
more able to handle these\ncases,\\r\\nthis PR also gives it a hard
100,000 iteration limit to\nprevent any\\r\\npossible infinite loops
we've missed.\\r\\n\\r\\nLastly, the\nSnooze Schedule APIs also come
with additional validation\nto\\r\\nhopefully prevent out of bounds
dates from ever being\nset.\\r\\n\\r\\n### Checklist\\r\\n\\r\\n- [x]
[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\\r\\n\\r\\n---------\\r\\n\\r\\nCo-authored-by:
kibanamachine\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi <[email protected]>\\r\\nCo-authored-by:
adcoelho\n<[email protected]>\",\"sha\":\"b30210929be0824f684f0b7d9d13bc936c1cbd22\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.x\",\"8.16\",\"8.17\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/205650\",\"number\":205650,\"mergeCommit\":{\"message\":\"[ResponseOps]\n[Alerting]
Handle invalid RRule params and prevent infinite
looping\n(#205650)\\n\\n##
Summary\\r\\n\\r\\nCloses\nhttps://github.com//issues/205558\\r\\n\\r\\nUpdates
the RRule\nlibrary to correctly handle some scenarios with\\r\\ninvalid
parameters\nthat would either cause it to return strange\\r\\nrecurrence
data or to\ninfinitely loop. Specifically:\\r\\n\\r\\n- On `RRule`
object creation,\nremoves and ignores any `bymonth`,\\r\\n`bymonthday`,
`byweekday`, or\n`byyearday` value that's out of bounds,\\r\\ne.g. less
than 0 or greater\nthan the number of possible months,
days,\\r\\nweekdays, etc.\\r\\n-\nSuccessfully ignores cases of
`BYMONTH=2, BYMONTHDAY=30`\n(February\\r\\n30th), an input that's
complicated to invalidate but still\nwon't
ever\\r\\noccur\\r\\n\\r\\nAllowing these values to go unhandled led
to\nunpredictable behavior. The\\r\\nRRule library uses Moment.js to
compare\ndates, but Moment.js months,\\r\\ndays, and other values
generally start\nat `0` while RRule values start\\r\\nat `1`. That led
to several\ncircumstances where we passed Moment.js a\\r\\nvalue of
`-1`, which\nMoment.js interpreted as moving to the\\r\\n***previous***
year, month, or\nother period of time.\\r\\n\\r\\nAt worst, this could
cause an infinite loop\nbecause the RRule library\\r\\nwas constantly
iterating through the wrong\nyear, never reaching the date\\r\\nit was
supposed to end on.\\r\\n\\r\\nIn\naddition to making the RRule library
more able to handle these\ncases,\\r\\nthis PR also gives it a hard
100,000 iteration limit to\nprevent any\\r\\npossible infinite loops
we've missed.\\r\\n\\r\\nLastly, the\nSnooze Schedule APIs also come
with additional validation\nto\\r\\nhopefully prevent out of bounds
dates from ever being\nset.\\r\\n\\r\\n### Checklist\\r\\n\\r\\n- [x]
[Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most
common\nscenarios\\r\\n\\r\\n---------\\r\\n\\r\\nCo-authored-by:
kibanamachine\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi\n<[email protected]>\\r\\nCo-authored-by:\nJanki
Salvi <[email protected]>\\r\\nCo-authored-by:
adcoelho\n<[email protected]>\",\"sha\":\"b30210929be0824f684f0b7d9d13bc936c1cbd22\"}},{\"branch\":\"8.x\",\"label\":\"v8.18.0\",\"branchLabelMappingKey\":\"^v8.18.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"8.16\",\"label\":\"v8.16.3\",\"branchLabelMappingKey\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"8.17\",\"label\":\"v8.17.1\",\"branchLabelMappingKey\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Zacqary Adam Xeper
<[email protected]>"}},{"branch":"8.16","label":"v8.16.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Zacqary Adam Xeper <[email protected]>
crespocarlos pushed a commit to crespocarlos/kibana that referenced this pull request Jan 8, 2025
…nite looping (elastic#205650)

## Summary

Closes elastic#205558

Updates the RRule library to correctly handle some scenarios with
invalid parameters that would either cause it to return strange
recurrence data or to infinitely loop. Specifically:

- On `RRule` object creation, removes and ignores any `bymonth`,
`bymonthday`, `byweekday`, or `byyearday` value that's out of bounds,
e.g. less than 0 or greater than the number of possible months, days,
weekdays, etc.
- Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30` (February
30th), an input that's complicated to invalidate but still won't ever
occur

Allowing these values to go unhandled led to unpredictable behavior. The
RRule library uses Moment.js to compare dates, but Moment.js months,
days, and other values generally start at `0` while RRule values start
at `1`. That led to several circumstances where we passed Moment.js a
value of `-1`, which Moment.js interpreted as moving to the
***previous*** year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library
was constantly iterating through the wrong year, never reaching the date
it was supposed to end on.

In addition to making the RRule library more able to handle these cases,
this PR also gives it a hard 100,000 iteration limit to prevent any
possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to
hopefully prevent out of bounds dates from ever being set.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: adcoelho <[email protected]>
@fake-haris
Copy link
Contributor

Are there any user facing changes that I can test for this PR, if so how? Thank you!

CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Jan 13, 2025
…nite looping (elastic#205650)

## Summary

Closes elastic#205558

Updates the RRule library to correctly handle some scenarios with
invalid parameters that would either cause it to return strange
recurrence data or to infinitely loop. Specifically:

- On `RRule` object creation, removes and ignores any `bymonth`,
`bymonthday`, `byweekday`, or `byyearday` value that's out of bounds,
e.g. less than 0 or greater than the number of possible months, days,
weekdays, etc.
- Successfully ignores cases of `BYMONTH=2, BYMONTHDAY=30` (February
30th), an input that's complicated to invalidate but still won't ever
occur

Allowing these values to go unhandled led to unpredictable behavior. The
RRule library uses Moment.js to compare dates, but Moment.js months,
days, and other values generally start at `0` while RRule values start
at `1`. That led to several circumstances where we passed Moment.js a
value of `-1`, which Moment.js interpreted as moving to the
***previous*** year, month, or other period of time.

At worst, this could cause an infinite loop because the RRule library
was constantly iterating through the wrong year, never reaching the date
it was supposed to end on.

In addition to making the RRule library more able to handle these cases,
this PR also gives it a hard 100,000 iteration limit to prevent any
possible infinite loops we've missed.

Lastly, the Snooze Schedule APIs also come with additional validation to
hopefully prevent out of bounds dates from ever being set.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Co-authored-by: adcoelho <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework release_note:fix Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.3 v8.17.1 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Response Ops][Alerting] isSnoozeActive can cause Kibana to hang for invalid rRule parameters
8 participants