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

[8.x] [ResponseOps] [Alerting] Handle invalid RRule params and prevent infinite looping (#205650) #205803

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

kibanamachine
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

…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 kibanamachine merged commit a02fcb2 into elastic:8.x Jan 7, 2025
11 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
alerting 220 222 +2

cc @Zacqary

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants