From dfcc20a114415e51d2bd6a5c48dd178f7a64a72a Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Mon, 23 Nov 2026 08:41:51 +0000 Subject: [PATCH] Stop go-org logging to stderr Parse warnings echo document content, so untrusted input could write arbitrary lines to the host process's stderr. --- markup_test.go | 21 +++++++++++++++++++++ org.go | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/markup_test.go b/markup_test.go index 1f17d33..2585e25 100644 --- a/markup_test.go +++ b/markup_test.go @@ -1,6 +1,7 @@ package markup import ( + "io" "os" "path/filepath" "strings" @@ -487,6 +488,26 @@ func TestRenderOrgDoesNotReadFiles(t *testing.T) { } } +func TestRenderOrgDoesNotWriteToStderr(t *testing.T) { + stderr := os.Stderr + pr, pw, err := os.Pipe() + if err != nil { + t.Fatal(err) + } + os.Stderr = pw + defer func() { os.Stderr = stderr }() + + _, renderErr := NewDefaultRegistry().Render("README.org", []byte("#+INCLUDE: \"/nonexistent\"\n\ntext [fn:missing]\n")) + _ = pw.Close() + out, readErr := io.ReadAll(pr) + if renderErr != nil || readErr != nil { + t.Fatalf("render: %v, read: %v", renderErr, readErr) + } + if len(out) != 0 { + t.Errorf("unexpected stderr output: %s", out) + } +} + // --- External renderers --- func TestRenderAsciiDocDoesNotReadFiles(t *testing.T) { diff --git a/org.go b/org.go index ada6cfc..194b460 100644 --- a/org.go +++ b/org.go @@ -18,7 +18,7 @@ func NewOrgRenderer() *OrgRenderer { } func (r *OrgRenderer) Render(content []byte) (string, error) { - conf := org.New() + conf := org.New().Silent() // #+INCLUDE and #+SETUPFILE would otherwise read arbitrary local files. conf.ReadFile = func(string) ([]byte, error) { return nil, errFileAccessDisabled