rc: fix leaking stack traces on panics GHSA-gwfq-86j8-7qhv

Before this change, rclone sent stack traces to the client on panic
capture in the rc. Stack traces can leak information which could be
useful to an attacker.
This commit is contained in:
Nick Craig-Wood
2026-07-31 13:21:59 +01:00
parent 1df2b70753
commit ff43a1e3ae
2 changed files with 9 additions and 1 deletions
+5 -1
View File
@@ -108,7 +108,11 @@ func (job *Job) OnFinish(fn func()) func() {
func (job *Job) run(ctx context.Context, fn rc.Func, in rc.Params) {
defer func() {
if r := recover(); r != nil {
job.finish(nil, fmt.Errorf("panic received: %v \n%s", r, string(debug.Stack())))
// Log the full stack trace server-side only - it must not
// be returned to the rc caller as it leaks internal paths,
// dependency versions and memory addresses.
fs.Errorf(nil, "rc: job %d panic: %v\n%s", job.ID, r, string(debug.Stack()))
job.finish(nil, fmt.Errorf("panic received: %v", r))
}
}()
job.finish(fn(ctx, in))
+4
View File
@@ -234,6 +234,10 @@ func TestJobRunPanic(t *testing.T) {
assert.Equal(t, rc.Params{}, job.Output)
assert.True(t, job.Duration >= floatSleepTime)
assert.Contains(t, job.Error, "panic received: boom")
// The stack trace must not be leaked to the rc caller - it is
// logged server-side only.
assert.NotContains(t, job.Error, "goroutine")
assert.NotContains(t, job.Error, "runtime/debug.Stack")
assert.Equal(t, false, job.Success)
assert.Equal(t, true, job.Finished)
job.mu.Unlock()