Skip to content

fix: bound sync-window duration parsing to prevent ReDoS - #329

Merged
keithchong merged 2 commits into
redhat-developer:mainfrom
aali309:GITOPS-12037
Nov 17, 2026
Merged

keithchong merged 2 commits into
redhat-developer:mainfrom
aali309:GITOPS-12037

Conversation

@aali309

@aali309 aali309 commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

see: GITOPS-12037

This PR

  • Fixes ReDoS when sorting AppProject sync windows by duration
  • Rejects overlong/malformed durations in the UI; keep sort order stable for mixed valid/invalid values
  • Sync windows tab still shows and sorts normal durations (1h, 2h30m)
  • Bad duration shows Invalid duration (tooltip has original)

Invalid or nill durations

Screenshot 2026-11-16 at 4 19 12 PM

All valid durations
Screenshot 2026-11-16 at 4 07 40 PM

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Sync window durations are sorted by duration rather than text, with invalid values placed after valid ones.
    • Empty durations display as “-”. Invalid durations are identified and show the original value in a tooltip.
  • New Features
    • Added the “Reconciliations (24h sliding window)” label in English and an “Invalid duration” message entry across supported locales. In some locales, the message currently appears in English.

The change adds bounded sync-window duration parsing, validation, and comparison. The Project Sync Windows tab uses the comparator for sorting and displays invalid values with a translated label and tooltip. Locale files add the invalid-duration message and add or reposition the reconciliation label.

Changes: Sync-window duration handling

Layer / File(s) Summary
Duration parsing and comparison
src/gitops/components/project/parseDurationToMinutes.ts, src/gitops/components/project/parseDurationToMinutes.test.ts
The duration utilities parse and validate bounded duration strings. The comparator orders valid durations by value, places valid durations before invalid ones, and treats two invalid durations as equal. Tests cover supported and malformed inputs, ordering, and comparator properties.
Project tab sorting and display
src/gitops/components/project/ProjectSyncWindowsTab.tsx, locales/*/plugin__gitops-plugin.json
The project tab uses the comparator for duration sorting. It displays valid durations unchanged and renders invalid values with a translated label and a tooltip containing the original value, truncated at the configured maximum length. Locale files add the invalid-duration message and add or reposition the reconciliation label.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: anandf

Merge Risk: Minimal · up to be407

This change bounds sync-window duration parsing so the Sync Windows tab no longer risks pathological regex work, and it shows "Invalid duration" for malformed values. Normal durations display and sort as before. No merge-blocking issues were found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: bounding sync-window duration parsing to prevent ReDoS. The changeset adds length-limited parsing (MAX_SYNC_WINDOW_DURATION_LENGTH, 64 characters), a bounded regex-fre…
Description check Passed The description states the purpose (fixing ReDoS in sync-window duration sorting), the UI behavior (rejecting overlong or malformed durations, showing Invalid duration with a tooltip), and the expecte…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: bounding sync-window duration parsing to prevent ReDoS. The changeset adds length-limited parsing (MAX_SYNC_WINDOW_DURATION_LENGTH, 64 characters), a bounded regex-free approach for duration parsing, validation, and comparison, and updates ProjectSyncWindowsTab to use them. The title is concise, specific, and matches the primary intent in the description and objectives.

Full details: Description check

Explanation

The description states the purpose (fixing ReDoS in sync-window duration sorting), the UI behavior (rejecting overlong or malformed durations, showing Invalid duration with a tooltip), and the expected behavior for valid durations such as 1h and 2h30m. It also links the tracking issue and includes screenshots. This content relates directly to the changeset.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73c19ee9-cd88-4c98-89a6-84949a2c854c
Commits

Reviewing files that changed from the base of the PR and between 31fc502 and be407b3.

Files selected for processing: 5

  • locales/es/plugin__gitops-plugin.json
  • locales/fr/plugin__gitops-plugin.json
  • locales/ja/plugin__gitops-plugin.json
  • locales/ko/plugin__gitops-plugin.json
  • locales/zh/plugin__gitops-plugin.json
Files skipped from review as they are similar to previous changes: 5

  • locales/es/plugin__gitops-plugin.json
  • locales/fr/plugin__gitops-plugin.json
  • locales/ja/plugin__gitops-plugin.json
  • locales/ko/plugin__gitops-plugin.json
  • locales/zh/plugin__gitops-plugin.json

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov-commenter

codecov-commenter commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.01587% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 15.37%. Comparing base (3bd1dab) to head (be407b3).
⚠️ Report is 109 commits behind head on main.

Files with missing lines Patch % Lines
...itops/components/project/ProjectSyncWindowsTab.tsx 0.00% 15 Missing ⚠️
...itops/components/project/parseDurationToMinutes.ts 95.83% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #329      +/-   ##
==========================================
+ Coverage   11.30%   15.37%   +4.07%     
==========================================
  Files         169      233      +64     
  Lines        6679     8499    +1820     
  Branches     2235     2808     +573     
==========================================
+ Hits          755     1307     +552     
- Misses       5923     7190    +1267     
- Partials        1        2       +1     
Flag Coverage Δ
unit-tests 15.37% <73.01%> (+4.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aali309

aali309 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

@keithchong, decided to not not hard code translation because I saw that you had separate PRs for translation. Please let me know if I should revert the last translation commit for the sake of time.

@aali309
aali309 marked this pull request as ready for review November 16, 2026 22:19
const bInvalid = Number.isNaN(bMinutes);

if (aInvalid && bInvalid) {
return a.localeCompare(b);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If both are NaN, do we really need to compare them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I will return a 0.

@keithchong

Copy link
Copy Markdown
Collaborator

@keithchong, decided to not not hard code translation because I saw that you had separate PRs for translation. Please let me know if I should revert the last translation commit for the sake of time.

Leave it in

keithchong
keithchong previously approved these changes Nov 17, 2026
Signed-off-by: Atif Ali <atali@redhat.com>
Signed-off-by: Atif Ali <atali@redhat.com>

@keithchong keithchong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @aali309 for getting this complete so quickly. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants