Skip to content

Commit 1daabf5

Browse files
Nikola-3ngrujic
and
ngrujic
authored
Sanitise user input in reporter runner (#9757)
* add type check * sanitise event input in reporter runner * revert package.json change to cli reporter --------- Co-authored-by: ngrujic <[email protected]>
1 parent a2789a4 commit 1daabf5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/core/core/src/ReporterRunner.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import logger, {
2121
import PluginOptions from './public/PluginOptions';
2222
import BundleGraph from './BundleGraph';
2323
import {tracer, PluginTracer} from '@parcel/profiler';
24+
import {anyToDiagnostic} from '@parcel/diagnostic';
2425

2526
type Opts = {|
2627
options: ParcelOptions,
@@ -85,7 +86,16 @@ export default class ReporterRunner {
8586
this.report(event);
8687
};
8788

88-
async report(event: ReporterEvent) {
89+
async report(unsanitisedEvent: ReporterEvent) {
90+
let event: ReporterEvent = unsanitisedEvent;
91+
if (event.diagnostics) {
92+
// Sanitise input before passing to reporters
93+
// $FlowFixMe too complex to narrow down by type
94+
event = {
95+
...event,
96+
diagnostics: anyToDiagnostic(event.diagnostics),
97+
};
98+
}
8999
for (let reporter of this.reporters) {
90100
let measurement;
91101
try {
@@ -95,6 +105,7 @@ export default class ReporterRunner {
95105
measurement = tracer.createMeasurement(reporter.name, 'reporter');
96106
}
97107
await reporter.plugin.report({
108+
// $FlowFixMe
98109
event,
99110
options: this.pluginOptions,
100111
logger: new PluginLogger({origin: reporter.name}),

packages/core/diagnostic/src/diagnostic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export type Diagnostifiable =
114114
/** Normalize the given value into a diagnostic. */
115115
export function anyToDiagnostic(input: Diagnostifiable): Array<Diagnostic> {
116116
if (Array.isArray(input)) {
117-
return input;
117+
return input.flatMap(e => anyToDiagnostic(e));
118118
} else if (input instanceof ThrowableDiagnostic) {
119119
return input.diagnostics;
120120
} else if (input instanceof Error) {

0 commit comments

Comments
 (0)