Repository navigation
Set a match timeout on every regex - #4451
Conversation
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
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4451/ Sample changed pages: |
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
| 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)] |
There was a problem hiding this comment.
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
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]>
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.mdnow 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 toAGENTS.mdsaying 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,ChangelogTextUtilitiesfrom #4445) set one.What
Shared timeout constant
RegexTimeoutsinElastic.DocumentationholdsMatchTimeoutMilliseconds(aconst, usable in attributes) andMatchTimeout(aTimeSpan) at 10 seconds.Source-generated regexes
Every
[GeneratedRegex]attribute acrosssrc/,tests/andtests-shared/now passesRegexTimeouts.MatchTimeoutMilliseconds. Where acultureNamewas already given, the timeout goes before it. The 5 attributes that already set 2000 ms (2 inCallOutParser, 3 inChangelogTextUtilitiesfrom #4445) are left as they are; a uniform value would be a follow-up.Other regex calls
The
new Regex(...)and staticRegex.Match/Matches/Replace/IsMatchcall sites now passRegexOptions.None, RegexTimeouts.MatchTimeout. Instance calls on generated regexes are covered by their attribute.Projects without
Elastic.DocumentationElastic.Documentation.Search.Contractanddocs-journeyscannot referenceElastic.Documentation, so each holds an internal copy of the constant (ContractRegexTimeouts,JourneysRegexTimeouts).Regression test
RegexTimeoutsTestsinElastic.Documentation.Build.Testsloads the repository'sElastic.*assemblies, invokes every[GeneratedRegex]member and fails when one has an infinite timeout.Project reference and guidance
Elastic.LegacyDocs.Migrationhad no project references, so it now referencesElastic.Documentationto reach the shared constant.AGENTS.mdgets a "Regex" rule in Code Style.Verify
Remove the timeout from one
[GeneratedRegex]andRegexTimeoutsTestsfails, naming it.🤖 Generated with Claude Code
https://claude.ai/code/session_01G9yddxccBiKoHhwUeatuvs
Generated by Claude Code