Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade marked to resolve ReDos vulnerability #2330

Merged
merged 4 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -18,7 +18,8 @@ jobs:
matrix:
node-version:
- 14.17
- 16
- 16.0.0
- 17
Trott marked this conversation as resolved.
Show resolved Hide resolved

runs-on: ubuntu-latest

Expand Down
22 changes: 15 additions & 7 deletions index.js
@@ -1,6 +1,5 @@
const {pick} = require('lodash');
const marked = require('marked');
const TerminalRenderer = require('marked-terminal');
const envCi = require('env-ci');
const hookStd = require('hook-std');
const semver = require('semver');
Expand All @@ -21,7 +20,16 @@ const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, pushNotes, getTagHea
const getError = require('./lib/get-error');
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');

marked.setOptions({renderer: new TerminalRenderer()});
let markedOptionsSet = false;
async function terminalOutput(text) {
if (!markedOptionsSet) {
const {default: TerminalRenderer} = await import('marked-terminal'); // eslint-disable-line node/no-unsupported-features/es-syntax
marked.setOptions({renderer: new TerminalRenderer()});
markedOptionsSet = true;
}

return marked.parse(text);
}

/* eslint complexity: off */
async function run(context, plugins) {
Expand Down Expand Up @@ -207,20 +215,20 @@ async function run(context, plugins) {
if (options.dryRun) {
logger.log(`Release note for version ${nextRelease.version}:`);
if (nextRelease.notes) {
context.stdout.write(marked(nextRelease.notes));
context.stdout.write(await terminalOutput(nextRelease.notes));
}
}

return pick(context, ['lastRelease', 'commits', 'nextRelease', 'releases']);
}

function logErrors({logger, stderr}, err) {
async function logErrors({logger, stderr}, err) {
const errors = extractErrors(err).sort((error) => (error.semanticRelease ? -1 : 0));
for (const error of errors) {
if (error.semanticRelease) {
logger.error(`${error.code} ${error.message}`);
if (error.details) {
stderr.write(marked(error.details));
stderr.write(await terminalOutput(error.details)); // eslint-disable-line no-await-in-loop
}
} else {
logger.error('An error occurred while running semantic-release: %O', error);
Expand All @@ -234,7 +242,7 @@ async function callFail(context, plugins, err) {
try {
await plugins.fail({...context, errors});
} catch (error) {
logErrors(context, error);
await logErrors(context, error);
}
}
}
Expand Down Expand Up @@ -265,7 +273,7 @@ module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env
throw error;
}
} catch (error) {
logErrors(context, error);
await logErrors(context, error);
unhook();
throw error;
}
Expand Down