Skip to content

Enhance script execution safety and add regex timeout handling#392

Open
gfs wants to merge 2 commits intomainfrom
gfs/Fixes
Open

Enhance script execution safety and add regex timeout handling#392
gfs wants to merge 2 commits intomainfrom
gfs/Fixes

Conversation

@gfs
Copy link
Copy Markdown
Contributor

@gfs gfs commented Apr 22, 2026

This pull request introduces several improvements to script and regex operation handling, focusing on security, reliability, and error reporting. The main changes include preventing unintended side effects during script validation, improving assembly reference resolution, and adding timeouts and error handling to regex operations.

gfs added 2 commits April 22, 2026 10:54
Defense in depth additional check to stop scripts from running when Analyzer.Options.RunScripts is false and return a clear Violation in validation or a failed OperationResult at runtime. Replace Assembly.Load usage with resolving assembly file paths and adding MetadataReference.CreateFromFile to avoid triggering module initializers; unresolved references now produce a Violation. Added ResolveAssemblyPath helper (checks loaded assemblies, AppContext.BaseDirectory, and runtime directory) and the System.IO import.
Wrap regex matching in a try/catch to handle RegexMatchTimeoutException and log a warning instead of crashing. Refactor the matching loops to correctly build and return TypedClauseCapture results for state1 and state2, and add a 5 second match timeout when constructing cached Regex instances to prevent long-running/DoS regex evaluations.
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.

1 participant