This document combines the identified vulnerabilities for the multierr
project into a single list, removing any duplicates and formatting each vulnerability with detailed descriptions as requested.
- Vulnerability Name: Untrusted Error Implementation Leading to Panic in Error Formatting
- Description:
An attacker who can supply a custom error value with a malicious implementation of the
Error()
orFormat()
method can force a panic when the error is later formatted or logged through multierr. The steps to trigger this vulnerability are as follows:- An attacker creates a custom error type (for example, a type named
maliciousError
) whoseError()
method (orFormat()
method) deliberately panics. - The attacker finds a way—for instance, through unvalidated input processing in the application—to have an instance of this malicious error injected into the error aggregation process (via calls to functions such as
multierr.Combine()
ormultierr.Append()
). - When the application later formats the aggregated error (by calling its
Error()
method or using formatted output such as%+v
), the multierr implementation calls the underlying error’s method without any protective wrapper. - The malicious method panics, causing the overall error formatting operation to panic and, in turn, crash the application.
- An attacker creates a custom error type (for example, a type named
- Impact: If this vulnerability is successfully triggered, it will cause an unexpected application crash due to an unhandled panic. In production, such a crash might lead to a loss of service and could also disrupt error logging and downstream monitoring—resulting in a potential denial of service situation.
- Vulnerability Rank: High
- Currently Implemented Mitigations:
- The multierr library calls the
Error()
(and, if available, theFormat()
method) on each aggregated error without wrapping these calls in a recovery or sanitization mechanism. - There is no explicit input validation or error method sandboxing in the code (for example, in
writeSingleline
orwriteMultiline
).
- The multierr library calls the
- Missing Mitigations:
- A safe error-formatting wrapper that uses a
recover()
block to catch panics triggered by custom error methods should be introduced. - Optional validation or sanitization of error messages (especially when they could have originated from untrusted sources) would reduce the risk of a malicious error implementation.
- A safe error-formatting wrapper that uses a
- Preconditions:
- The application that uses multierr must allow error values (or errors derived from external inputs) that are controlled or influenced by an attacker.
- The attacker must be able to inject a malicious error implementation into the error-handling path that is later aggregated by multierr.
- Source Code Analysis:
- In the function
multiError.writeSingleline(w io.Writer)
(found in error.go), the code iterates over the slicemerr.errors
and, for each item, immediately callsio.WriteString(w, item.Error())
. There is no panic prevention mechanism (such as a deferred recover) around the call toitem.Error()
. - Similarly, in
multiError.writeMultiline(w io.Writer)
, the call tofmt.Sprintf("%+v", item)
may invoke a customFormat()
method on a user-controlled error value. Again, no recovery from panics is provided. - Because neither function attempts to catch panics resulting from calling methods on the aggregated error values, a malicious implementation that panics will propagate its panic and crash the caller.
- In the function
- Security Test Case:
- Setup:
- Define a custom error type (e.g.,
maliciousError
) whoseError()
method immediately callspanic("malicious panic")
. - Create a benign error (for example, using
errors.New("normal error")
).
- Define a custom error type (e.g.,
- Aggregation:
- Use
multierr.Combine(maliciousError{}, normalError)
or a similar call (such as successive calls tomultierr.Append()
) to aggregate the malicious error with the benign error.
- Use
- Trigger:
- Invoke the
Error()
method on the resulting aggregated error (or format it usingfmt.Sprintf("%+v", aggregatedError)
).
- Invoke the
- Assertion:
- Verify that the call panics as expected (this can be done by wrapping the call in a test that asserts a panic is raised).
- Result:
- The successful detection of the panic confirms that an attacker who can inject such a malicious error would be able to cause a critical failure in any application that later formats the multierr error.
- Setup:
- Description:
An attacker who can supply a custom error value with a malicious implementation of the