Skip to content

Set a match timeout on every regex - #4451

Merged
Mpdreamz merged 10 commits into
mainfrom
claude/regex-match-timeouts
Nov 16, 2026
Merged

Mpdreamz merged 10 commits into
mainfrom
claude/regex-match-timeouts

Conversation

@claude

@claude claude Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Fabrizio Ferri Benedetti · Slack thread

Every regex in the repo now has a match timeout (10 seconds), so a pathological input fails fast instead of hanging a build indefinitely (ReDoS). AGENTS.md now requires a timeout on every regex.

Affects: Internals only

Prompt summary: Add a match timeout to every [GeneratedRegex] definition, even a generous one such as 10 seconds, to prevent ReDoS, and add a line to AGENTS.md saying all regexes must have a timeout.

Why

Most [GeneratedRegex] attributes had no match timeout, so a crafted or unlucky input could make a regex backtrack for an unbounded time. Only a handful of regexes (CallOutParser, ChangelogTextUtilities from #4445) set one.

What

Shared timeout constant

RegexTimeouts in Elastic.Documentation holds MatchTimeoutMilliseconds (a const, usable in attributes) and MatchTimeout (a TimeSpan) at 10 seconds.

Source-generated regexes

Every [GeneratedRegex] attribute across src/, tests/ and tests-shared/ now passes RegexTimeouts.MatchTimeoutMilliseconds. Where a cultureName was already given, the timeout goes before it. The 5 attributes that already set 2000 ms (2 in CallOutParser, 3 in ChangelogTextUtilities from #4445) are left as they are; a uniform value would be a follow-up.

Other regex calls

The new Regex(...) and static Regex.Match/Matches/Replace/IsMatch call sites now pass RegexOptions.None, RegexTimeouts.MatchTimeout. Instance calls on generated regexes are covered by their attribute.

Projects without Elastic.Documentation

Elastic.Documentation.Search.Contract and docs-journeys cannot reference Elastic.Documentation, so each holds an internal copy of the constant (ContractRegexTimeouts, JourneysRegexTimeouts).

Regression test

RegexTimeoutsTests in Elastic.Documentation.Build.Tests loads the repository's Elastic.* assemblies, invokes every [GeneratedRegex] member and fails when one has an infinite timeout.

Project reference and guidance

Elastic.LegacyDocs.Migration had no project references, so it now references Elastic.Documentation to reach the shared constant. AGENTS.md gets a "Regex" rule in Code Style.

Verify

mise run test   # 8996 passed, 2 skipped

Remove the timeout from one [GeneratedRegex] and RegexTimeoutsTests fails, naming it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G9yddxccBiKoHhwUeatuvs


Generated by Claude Code

Every [GeneratedRegex] now passes RegexTimeouts.MatchTimeoutMilliseconds
(10 seconds), and the remaining new Regex(...) and static Regex.* calls
pass RegexTimeouts.MatchTimeout, so a pathological input cannot hang a
build indefinitely (ReDoS). AGENTS.md now requires a timeout on every regex.

Elastic.LegacyDocs.Migration now references Elastic.Documentation for
the shared constant.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G9yddxccBiKoHhwUeatuvs
@claude claude Bot added the chore label Oct 14, 2026
@theletterf
theletterf marked this pull request as ready for review October 14, 2026 10:51
@theletterf
theletterf requested a review from a team as a code owner October 14, 2026 10:51
@theletterf
theletterf requested a review from Mpdreamz October 14, 2026 10:51
@github-actions

Copy link
Copy Markdown
Contributor

theletterf and others added 3 commits October 14, 2026 13:33
Resolve the GeneratedCodeSamples.cs conflict by keeping main's WithCredentials
and ApiKeyPair, and set the match timeout on the regexes main added since:
SchemaHelpers, SyntheticCodeSamples, ApiKeyPair, and three test Regex calls.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G9yddxccBiKoHhwUeatuvs
Resolve the ReleaseNotesExtractor.cs using conflict (main dropped the
Diagnostics using, we need Elastic.Documentation for RegexTimeouts) and set the
match timeout on the regexes main added since: DecisionLog, BackportReferences
(including its NonBacktracking regex), GitHubBackportService, and
GitHubBackportServiceTests.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G9yddxccBiKoHhwUeatuvs
Resolve the GitHubPrService.cs conflict by taking main's removal of
ExtractLinkedIssues (it moved to LinkedIssueExtractor) and set the match
timeout on the regexes main added since: LinkedIssueExtractor,
GraphQlPullRequestSummaryProvider, and the new test Regex calls.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G9yddxccBiKoHhwUeatuvs
…meouts

# Conflicts:
#	src/Elastic.ApiExplorer/Export/OpenApiDocumentExporter.cs
#	src/Elastic.ApiExplorer/Landing/TagLandingViewModel.cs
#	src/authoring/Elastic.LegacyDocs.Migration/Asciidoc/AsciidocParser.cs
#	src/services/Elastic.Changelog/GitHub/GitHubBackportService.cs
#	src/services/Elastic.Changelog/GitHub/GitHubCommitRangeService.cs
#	src/services/Elastic.Changelog/GitHub/GraphQlPullRequestSummaryProvider.cs
#	tests/Elastic.ApiExplorer.Tests/FieldDirectionTests.cs
#	tests/Elastic.ApiExplorer.Tests/OperationExamplesPanelRenderingTests.cs
#	tests/Elastic.ApiExplorer.Tests/ParameterRowsTests.cs
#	tests/Elastic.Changelog.Tests/Changelogs/GitHubBackportServiceTests.cs
#	tests/Elastic.Changelog.Tests/Changelogs/GitHubCommitRangeServiceTests.cs
#	tests/Elastic.Changelog.Tests/Changelogs/GraphQlPullRequestSummaryProviderTests.cs
Copilot AI requested a review from Mpdreamz November 4, 2026 14:02
public partial class OpenApiDocumentExporter(VersionsConfiguration versionsConfiguration, IDocumentInferrerService? documentInferrer = null)
{
[GeneratedRegex(@"\*\*[^*\n]*methods? and paths? for this operation:\*\*", RegexOptions.IgnoreCase)]
[GeneratedRegex(@"\*\*[^*\n]*methods? and paths? for this operation:\*\*", RegexOptions.IgnoreCase, RegexTimeouts.MatchTimeoutMilliseconds)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

Add regression coverage for the repository-wide finite-timeout guarantee. The existing AllRegexes_HaveAMatchTimeout test checks only ChangelogTextUtilities, not the regexes hardened here. It therefore misses omissions such as OperationPathSpanRegex immediately below this change and BlockquoteMarkerRegex in ReleaseNotesExtractor, which still use the infinite default. A test covering the affected regex factories would catch incomplete sweeps and prevent the protection from silently regressing.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

…meouts

# Conflicts:
#	tests/Elastic.ApiExplorer.Tests/OperationHeadingLevelTests.cs

Co-authored-by: Mpdreamz <[email protected]>
…meouts

# Conflicts:
#	tests/Elastic.Markdown.Tests/Inline/FootnotesTests.cs
…meouts

# Conflicts:
#	src/Elastic.ApiExplorer/Infrastructure/ApiSeoDescription.cs
#	src/services/Elastic.Changelog/Serverless/ServerlessPromotion.cs
#	tests/Elastic.ApiExplorer.Tests/ApiPropertyTreeBuilderTests.cs
Mpdreamz and others added 2 commits November 16, 2026 16:43
The first sweep left 22 files without a match timeout, including `OperationPathSpanRegex` and `BlockquoteMarkerRegex`, and a few tests built regexes without one. They now use the shared timeout. Two projects cannot reference `Elastic.Documentation`, so each holds a local copy of the constant.

`RegexTimeoutsTests` loads the repository's `Elastic.*` assemblies, invokes every `[GeneratedRegex]` member and fails when one has an infinite timeout.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Mpdreamz
Mpdreamz merged commit 9af75f1 into main Nov 16, 2026
44 checks passed
@Mpdreamz
Mpdreamz deleted the claude/regex-match-timeouts branch November 16, 2026 15:59
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