Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions components/git/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import UpdateSecurityRelease from '../../lib/update_security_release.js';
import SecurityBlog from '../../lib/security_blog.js';
import SecurityAnnouncement from '../../lib/security-announcement.js';
import { forceRunAsync } from '../../lib/run.js';
import { getAffectedVersionLines } from '../../lib/security-release/security-release.js';
import {
getAffectedVersionLines,
getLatestAffectedReleaseLine
} from '../../lib/security-release/security-release.js';
import { getPullRequestURLForLine } from '../../lib/prepare_release.js';

export const command = 'security [options]';
Expand Down Expand Up @@ -289,21 +292,39 @@ async function landingSession(cli, req, prURL, argv, cveIds = undefined) {
return false;
}
async function applySecurityPatches(cli) {
const { nodeMajorVersion } = await checkCwd({ nodeDir: process.cwd() });
const branch = `v${nodeMajorVersion}.x`;
let { nodeMajorVersion } = await checkCwd({ nodeDir: process.cwd() });
const credentials = await auth({
github: true
});
const req = new Request(credentials);

cli.info('N.B.: if there are commits on the staging branch that need to be included in the ' +
'security release, please rebase them manually and answer no to the following question');
const { owner, repo } = SECURITY_REPO;
const vulnerabilities = await fetchVulnerabilitiesDotJSON(cli, req);
const { releaseDate, reports, dependencies } = vulnerabilities;

let branch = `v${nodeMajorVersion}.x`;
let stagingBranch = `${branch}-staging`;
let label = branch;
const latestReleaseLine = getLatestAffectedReleaseLine(vulnerabilities);
if (latestReleaseLine < nodeMajorVersion) {
cli.info(`v${nodeMajorVersion}.x is not listed in vulnerabilities.json, ` +
`the most recent affected release line is v${latestReleaseLine}.x.`);
if (await cli.prompt(
`Do you want to apply on main the patches for v${latestReleaseLine}.x?`)) {
nodeMajorVersion = latestReleaseLine;
branch = stagingBranch = 'main';
label = `v${latestReleaseLine}.x`;
}
}

if (branch !== 'main') {
cli.info('N.B.: if there are commits on the staging branch that need to be included in ' +
'the security release, please rebase them manually and answer no to the following question');
}
// Try reset to the public upstream
const session = new Session(cli, process.cwd(), undefined, { branch });
await session.tryResetBranch();

const { owner, repo } = SECURITY_REPO;
const { releaseDate, reports, dependencies } = await fetchVulnerabilitiesDotJSON(cli, req);
const missingPatches = [];

let patchedVersion;
Expand All @@ -325,19 +346,19 @@ async function applySecurityPatches(cli) {
}

const existingCommits = (await forceRunAsync('git',
['--no-pager', 'log', `${session.upstream}/v${nodeMajorVersion}.x-staging`,
['--no-pager', 'log', `${session.upstream}/${stagingBranch}`,
'--grep', `^PR-URL: ${prURL}$`,
'--format=%H %h %s'],
{ ignoreFailure: false, captureStdout: true })).trim().split('\n');
if (existingCommits[0] === '') {
cli.error(`${prURL} was not found on ${session.upstream}/v${nodeMajorVersion}.x-staging.`);
cli.info('Please cherry-pick the adequate commits to the public staging branch.');
cli.error(`${prURL} was not found on ${session.upstream}/${stagingBranch}.`);
cli.info(`Please cherry-pick the adequate commits to ${session.upstream}/${stagingBranch}.`);
cli.info('Skipping');
cli.warn('The resulting HEAD will not be ready for a release proposal');
continue;
}
cli.info(`The following commit(s) have been found on ${session.upstream}/v${nodeMajorVersion
}.x-staging:\n${existingCommits.map(c => ` - ${c.slice(41)}`).join('\n')}`);
cli.info(`The following commit(s) have been found on ${session.upstream}/${stagingBranch
}:\n${existingCommits.map(c => ` - ${c.slice(41)}`).join('\n')}`);
if (!await cli.prompt('Cherry-pick those for the current proposal?')) {
cli.info('Skipping');
cli.warn('The resulting HEAD will not be ready for a release proposal');
Expand All @@ -350,9 +371,9 @@ async function applySecurityPatches(cli) {

cli.startSpinner(`Fetching open PRs on ${owner}/${repo}...`);
const { repository: { pullRequests: { nodes } } } = await req.gql('PRs', {
owner, repo, labels: [branch],
owner, repo, labels: [label],
});
cli.stopSpinner(`Fetched all PRs labeled for v${nodeMajorVersion}.x`);
cli.stopSpinner(`Fetched all PRs labeled for ${label}`);

for (const { affectedVersions, prURL, cveIds, patchedVersions } of reports) {
if (!getAffectedVersionLines(affectedVersions).includes(`${nodeMajorVersion}.x`)) continue;
Expand All @@ -364,7 +385,7 @@ async function applySecurityPatches(cli) {
let pr = nodes.find(({ url }) => url === prURL);
if (!pr) {
cli.info(
`${prURL} is not labelled for v${nodeMajorVersion}.x, there might be a backport PR.`
`${prURL} is not labelled for ${label}, there might be a backport PR.`
);

cli.startSpinner('Fetching PR title to find a match...');
Expand All @@ -380,7 +401,7 @@ async function applySecurityPatches(cli) {
);
pr = nodes.find(({ number }) => number === prID);
if (!pr) {
cli.error(`${prID} is not in the list of PRs labelled for v${nodeMajorVersion}.x`);
cli.error(`${prID} is not in the list of PRs labelled for ${label}`);
cli.info('The list of labelled PRs and vulnerabilities.json are fetched ' +
'once at the start of the session; to refresh those, start a new NCU session');
const response = await cli.prompt('Do you want to skip that CVE?',
Expand All @@ -393,7 +414,7 @@ async function applySecurityPatches(cli) {
}
}
}
cli.ok(`${pr.url} is labelled for v${nodeMajorVersion}.x.`);
cli.ok(`${pr.url} is labelled for ${label}.`);

const backport = prURL !== pr.url;

Expand All @@ -408,6 +429,10 @@ async function applySecurityPatches(cli) {
} else {
cli.ok('All patches are on the local HEAD!');
}
if (branch === 'main') {
cli.info('You can now build and test, and potentially push to a private staging branch');
return;
}
cli.info('You can now build and test, and create a proposal with the following commands:');
cli.info(`git switch -C v${nodeMajorVersion}.x HEAD`);
cli.info(`git node release --prepare --security --newVersion=${patchedVersion} ` +
Expand Down
23 changes: 18 additions & 5 deletions docs/git-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,13 @@ $ git node vote \

Manage or starts a security release process.

Every `git node security` action asks for permission before each mutating step.
Read-only operations, such as reading files or fetching report data, run without
confirmation. Each confirmation names the command or service action that will
write state and explains the side effect, such as writing files, committing and
pushing changes, creating issues, or updating HackerOne reports.
Every `git node security` action asks for permission before each step that
changes remote state, such as creating issues or pull requests, or updating
HackerOne reports. Local changes run without confirmation: files are written
and staged, and the commit message is pre-filled in `.git/MERGE_MSG`, so it is
picked up by `git commit` and editors such as VS Code. Apart from `--start`,
which pushes its draft through the GitHub API, the CLI never commits or pushes;
review the staged diff, then commit and push `next-security-release` yourself.

<a id="git-node-security-prerequisites"></a>

Expand Down Expand Up @@ -615,6 +617,13 @@ is configured with, not your local git credentials. That token needs:
pull request), plus **Pull requests: Read** on `nodejs-private/node-private`
to look up patch authors.

`git node security --request-cve` lists the reports without a CVE and asks for
a single confirmation. It then requests a CVE for each report and adds the CVE
ID to the HackerOne report right away, without further prompts.
`vulnerabilities.json` is updated and staged last, so if that step fails or the
run is interrupted, `git node security --sync` can still fetch the CVE IDs from
HackerOne.

#### Optional: reserve CVEs through the OpenJS Foundation CNA

By default `--request-cve` reserves CVE ids through HackerOne, which acts as
Expand Down Expand Up @@ -710,6 +719,10 @@ This command fetches the list of reports and the list of PRs labelled for the
release corresponding to the CWD, and match them in pair, and run a
`git node land` session for each.

When run on `main` (i.e. the CWD's major version is greater than the most
recent release line listed in `vulnerabilities.json`), it offers to apply the
patches of that most recent release line on top of `main` instead.

### `git node security --update-date=YYYY/MM/DD`

This command updates the `vulnerabilities.json` with target date of the security release.
Expand Down
8 changes: 4 additions & 4 deletions lib/prepare_security.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import {
NEXT_SECURITY_RELEASE_BRANCH,
NEXT_SECURITY_RELEASE_FOLDER,
commitAndPushVulnerabilitiesJSON,
stageSecurityReleaseChanges,
validateDate,
promptDependencies,
getSupportedVersions,
Expand Down Expand Up @@ -195,11 +195,11 @@ export default class PrepareSecurityRelease extends SecurityRelease {
vulnerabilityJSON.releaseDate}?`,
{ defaultAnswer: true });
if (updateFolder) {
await this.updateReleaseFolder(
this.updateReleaseFolder(
vulnerabilityJSON.releaseDate.replaceAll('/', '-')
);
const securityReleaseFolder = path.join(process.cwd(), 'security-release');
await commitAndPushVulnerabilitiesJSON(
await stageSecurityReleaseChanges(
securityReleaseFolder,
'chore: change next-security-release folder',
{ cli: this.cli, repository: this.repository }
Expand Down Expand Up @@ -290,7 +290,7 @@ export default class PrepareSecurityRelease extends SecurityRelease {
description: 'Add every triaged report and summarize missing information'
}
],
{ defaultAnswer: 'review' }
{ defaultAnswer: 'include-all' }
);
}

Expand Down
15 changes: 5 additions & 10 deletions lib/security-announcement.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from 'node:fs';
import {
NEXT_SECURITY_RELEASE_REPOSITORY,
checkoutOnSecurityReleaseBranch,
getVulnerabilitiesJSON,
getVulnerabilitiesJSONPath,
validateDate,
formatDateToYYYYMMDD,
commitAndPushVulnerabilitiesJSON,
createIssue,
writeSecurityFile
stageSecurityReleaseChanges,
createIssue
} from './security-release/security-release.js';
import auth from './auth.js';
import Request from './request.js';
Expand Down Expand Up @@ -47,14 +47,9 @@ export default class SecurityAnnouncement {
content.buildIssue = await this.createBuildWGIssue(releaseDate);

const vulnerabilitiesJSONPath = getVulnerabilitiesJSONPath();
await writeSecurityFile(
cli,
vulnerabilitiesJSONPath,
JSON.stringify(content, null, 2),
'This records the build and docker tracking issue links in vulnerabilities.json.'
);
fs.writeFileSync(vulnerabilitiesJSONPath, JSON.stringify(content, null, 2));
const commitMessage = 'chore: add build and docker issue link';
await commitAndPushVulnerabilitiesJSON([vulnerabilitiesJSONPath],
await stageSecurityReleaseChanges([vulnerabilitiesJSONPath],
commitMessage, { cli: this.cli, repository: this.repository });

this.cli.ok('Added docker and build issue in vulnerabilities.json');
Expand Down
Loading
Loading