Skip to content

Secret masking is quadratic in line length: URL-credentials mask hint runs without NonBacktracking or a timeout #4798

Open

Description

@freben

Describe the bug

A step that prints one long line (hundreds of kilobytes or more) makes Runner.Worker use 100% of one CPU core for minutes to hours. The job log stops updating, and the step runs until it hits its timeout. The machine itself stays healthy.

The cause is in secret masking: RegexSecret compiles each regex mask hint from the job message as new Regex(pattern), with the backtracking interpreter, no match timeout and no RegexOptions.NonBacktracking. One of the mask hints the service sends, a pattern for credentials in URLs, takes time quadratic in the line length.

This is the root cause of #1031 ("Long log lines slow down the runner", open since 2021), which reports the same slowdown on GitHub-hosted runners.

To Reproduce

  1. Add a step that prints one long line:
    - run: python3 -c "print('x' * 1_000_000)"
  2. Run the workflow.
  3. The step should take a second, but it takes many minutes: on our runner VM, masking a line of this length took about 20 minutes. Long log lines slow down the runner #1031 reports 17 to 26 minutes for a line of about 1 MB.

The regex on its own, without the runner. In a dotnet new console project on .NET 8:

using System.Diagnostics;
using System.Text.RegularExpressions;

// Same shape as the URL-credentials mask hint: unanchored scheme, "://",
// user, ":", password, "@".
var pattern = @"(?:[a-zA-Z][a-zA-Z\d+-.]*):\/\/([a-zA-Z\d\-._~\!$&'()*+,;=%]+):([a-zA-Z\d\-._~\!$&'()*+,;=:%]*)@";
foreach (var (name, regex) in new[] {
    ("default", new Regex(pattern)),
    ("NonBacktracking", new Regex(pattern, RegexOptions.NonBacktracking)) })
{
    foreach (var size in new[] { 10_000, 50_000, 100_000, 200_000 })
    {
        var line = new string('x', size);
        var sw = Stopwatch.StartNew();
        regex.Match(line);
        Console.WriteLine($"{name,-16} {size,8} chars: {sw.Elapsed.TotalSeconds:F3} s");
    }
}

Output on an Apple M-series laptop with .NET 8.0.426:

Line length Default options (as in RegexSecret) RegexOptions.NonBacktracking
10,000 0.049 s 0.005 s
50,000 1.04 s 0.000 s
100,000 3.36 s 0.000 s
200,000 13.5 s 0.000 s

Doubling the length takes four times as long. The scheme part [a-zA-Z][a-zA-Z\d+-.]* has no anchor: at every starting position it consumes the rest of a run of letters, then backtracks looking for ://.

Expected behavior

Masking a line takes time roughly linear in its length, and a long line slows a step down by seconds at most.

Runner Version and Platform

What's not working?

Stack samples of the busy Runner.Worker thread, taken with dotnet-stack report, the same in every affected job:

System.Text.RegularExpressions.RegexInterpreter.TryMatchAtCurrentPosition
System.Text.RegularExpressions.RegexInterpreter.Scan
System.Text.RegularExpressions.Regex.RunSingleMatch
Sdk!GitHub.DistributedTask.Logging.RegexSecret+<GetPositions>d__3.MoveNext()
Sdk!GitHub.DistributedTask.Logging.SecretMasker.MaskSecrets(class System.String)
Runner.Worker!GitHub.Runner.Worker.ExecutionContext.Write(class System.String,class System.String)
Runner.Worker!GitHub.Runner.Worker.Handlers.OutputManager.OnDataReceived(...)
Runner.Sdk!GitHub.Runner.Sdk.ProcessInvoker.ProcessOutput()

In the runner source:

  • Worker.cs adds every mask hint of type Regex with HostContext.SecretMasker.AddRegex(maskHint.Value).
  • RegexSecret compiles it with new Regex(pattern).
  • SecretMasker.MaskSecrets runs every regex secret over every output line.

We timed each of the 24 regex mask hints our jobs receive, the way RegexSecret.GetPositions runs them, on a runner VM. The line was - "text": "xxx…x",, which is what a failing test assertion on a large string prints.

Line length URL-credentials mask hint Each of the other 23
100,000 characters 11 s < 0.01 s
1 MiB 1,205 s < 0.1 s
9 MiB not measured; about a day if quadratic < 0.01 s

Our trigger was a 9 MiB line, so the step never recovered.

Suggested fixes; any one of them keeps a single line from stalling the job:

  • Create regex secrets with RegexOptions.NonBacktracking (.NET 7 and later), which matches in linear time. As the table above shows, it removes the cost entirely for this pattern.
  • Or give them a match timeout, for example new Regex(pattern, RegexOptions.None, TimeSpan.FromSeconds(1)). On RegexMatchTimeoutException, mask the whole line rather than skip it, so that a timeout can't leak a secret.
  • On the service side, anchor the scheme in the URL-credentials hint, for example with \b and a length cap such as [a-zA-Z][a-zA-Z\d+\-.]{0,30}.

Job Log Output

Nothing is printed: the log simply stops at the long line, and then the step times out. For example:

##[error]The action 'test' has timed out after 60 minutes.

Runner and Worker's Diagnostic Logs

The Worker_ log shows nothing unusual while the thread spins. Its last lines are the usual periodic entries, and there are no errors or warnings.

Activity

  1. added
    bug
    on Oct 20, 2026
  2. kiansdi commented on Nov 1, 2026

    @kiansdi

    We hit this too, on a second setup: runner 2.338.2, Linux x64, ephemeral ARC runners on Kubernetes (gha-runner-scale-set 0.15.0).

    Our trigger was a pytest test parametrized with "y" * 1_000_000. Pytest builds the test ID from the value, so the ID is ~1,000,114 characters; with pytest -q --durations=25, whenever that test ranked in the 25 slowest, the ID was printed as one line and the step hung until the job timeout. It happened twice, both times on the shard holding that test, and looked like a random hang because it depends on timing (re-runs passed).

    Captured from the stuck pod:

    • one .NET TP Worker thread at ~91% CPU in user mode (no syscall), every other thread blocked in futex/poll;
    • STDOUT/STDERR stream read finished logged, but never Finished process;
    • the last live-console batch and the step page both end in the --durations block, before the test with the 1 MB ID;
    • no step process left.

    This matches the stack in the report (ProcessInvoker.ProcessOutput → OutputManager.OnDataReceived → SecretMasker.MaskSecrets). Because output handlers run on the same task that waits for the process exit, the step cannot complete until masking finishes.

    We worked around it by giving long parametrize values short IDs and capping each output line at 4,000 characters, but a runner-side fix (RegexOptions.NonBacktracking, or a match timeout that masks the whole line) would protect anyone whose tools print one long line. Related: #1031.

  3. Jster42 commented on Nov 9, 2026

    @Jster42

    We hit exactly this in the wild — adding a real-world repro and workaround for anyone else who lands here.

    Case: a step running cosign attest-blob (sigstore) — which echoes its full attestation bundle to stdout as a single line even when --bundle writes it to disk — stalled identically on a self-hosted linux x64 runner (2.338.2) AND on ubuntu-latest hosted. For a large predicate the line was ~24.7 MB.

    Signature: the step's bash completed all work and was fully reaped, stdout/stderr stream reads finished, zero child processes — yet the step reported in_progress indefinitely (timeout-minutes did not fire, consistent with enforcement sharing the stalled path). Killing the worker was the only recovery. Three of three runs containing the unredirected step wedged.

    A/B proof, same step content:

    • unredirected cosign stdout → wedged at +25 min
    • cosign stdout > /dev/null or > file → step completes in ~22 s

    Minimal repro: python3 -c "print('x'*25000000)" in any step body reproduces the stall without cosign — a ~25 MB single line is sufficient.

    Consistent with this issue's diagnosis: the per-line secret-mask scan is quadratic in line length. Until the mask scan gets NonBacktracking/a timeout (or line chunking), workaround for others: redirect any tool that can emit multi-MB single-line output to a file or /dev/null — cosign's --bundle file has the same content, so the echo is dispensable noise.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions