github.com/yuin/goldmark v1.7.17: cozy-stack's span inline parser rescans the rest of the line at every `[`

Open Beginner friendly
#5,374 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go

Research direction

Start at model/note/custom/span.go:52-75, where spanParser.Parse scans forward from each [ to the next ], and read its registration on trigger [ in model/note/markdown.go:572. Trace how goldmark calls inline parsers per byte, then bound the scan as the report suggests and add a test that parses 200000 [ characters within a time budget. Done means the parser no longer rescans the rest of the line for every bracket and the new test passes.

Written by the indexing model from the issue text.

Description

ai-driven-qa bug claude Minor

Severity: Minor — a limited or confusing misbehaviour, of a secondary feature or in an edge case.

  • Severity: medium. A line of about 2 million [ without ] costs about 2·10¹² byte comparisons, which is tens of minutes of CPU by the loop count (not measured). It runs in the request goroutine and cannot be cancelled. Authenticated attacker, availability only.
  • CVSS 3.1: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H — 6.5
  • Found by: claude
  • Where: model/note/custom/span.go:52-75 (spanParser.Parse), registered on trigger [ at model/note/markdown.go:572
  • Report on: linagora/cozy-stack
  • Introduced by: sha=723540f3a1963bf49542f66a03f30642f25809e3 pr=none confidence=likely — "Start working on inline markdown common attributes" (2021-11-17). This commit added the forward scan to the first ] of the line, with nothing remembered between calls. 7e2801417905c4ee81371c04751aa9f15e8d110f ("Fix span with attributes parsing", 2021-11-18) and c2e8b9d00542b50fb9fbe6d0f11d304b6d321439 ("Fix a panic when parsing note markdown", 2021-12-13) changed the body without changing the scan.
  • Weakness: goldmark's parseBlock calls every inline parser registered for a byte at each position where the byte occurs, and moves on by one byte when the parser returns nil. For every [:
    line, _ := block.PeekLine()
    for pos := 1; pos < len(line); pos++ {
        if line[pos] == ']' {
    
    scans up to the end of the line (2 MiB), so N [ cost N²/2. goldmark's own link parser, which also triggers on [, stays linear on this input. The quadratic cost therefore comes from the custom parser. Not a taint flow. Confirmed by reading the loop and the dispatch in goldmark's parseBlock.
  • Impact: CPU denial of service for every instance on the server. No data is exposed.
  • Remediation: bound the scan. Spans are short, so stop at a fixed length (e.g. 1 000 bytes) or at the next [:
    for pos := 1; pos < len(line) && pos < maxSpanLabel; pos++ {
        if line[pos] == '[' { return nil }
        if line[pos] == ']' { ... }
    
    Alternatively, compute the position of the next ]{ once per line and keep it in the parser Context. Add a test that parses "["×200000 within a time budget. Running parseFile in a worker with a deadline would also bound SEV-1 to SEV-3.

Finding SEV-4 (medium) of the twake-qa deep dependency review of cozy-stack: github.com/yuin/goldmark v1.7.17 (yuin/goldmark at v1.7.17); full report: deep-dependency-reviews/20261122-204318-eed494-github-com-yuin-goldmark.md.


Found by automated QA (twake-qa, claude -p + deep dependency review) on cb46bbc4eca2, severity: minor, browsers: none, first seen 2026-11-22.

Dominant language
Go
Stars
1.3k
Forks
147
Avg merge
1d 19h
Merged PRs (30d)
146

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from linagora/cozy-stack

All issues in linagora/cozy-stack

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.