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

Enforces sha512 in the cache #7591

Merged
merged 3 commits into from Oct 2, 2019
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
2 changes: 1 addition & 1 deletion src/constants.js
Expand Up @@ -28,7 +28,7 @@ export const YARN_INSTALLER_MSI = 'https://yarnpkg.com/latest.msi';
export const SELF_UPDATE_VERSION_URL = 'https://yarnpkg.com/latest-version';

// cache version, bump whenever we make backwards incompatible changes
export const CACHE_VERSION = 5;
export const CACHE_VERSION = 6;

// lockfile version, bump whenever we make backwards incompatible changes
export const LOCKFILE_VERSION = 1;
Expand Down
6 changes: 4 additions & 2 deletions src/fetchers/tarball-fetcher.js
Expand Up @@ -166,9 +166,11 @@ export default class TarballFetcher extends BaseFetcher {
this.remote.integrity !== this.validateIntegrity.toString()
) {
this.remote.integrity = this.validateIntegrity.toString();
} else if (this.validateIntegrity) {
this.remote.cacheIntegrity = this.validateIntegrity.toString();
}

if (integrityInfo.algorithms.length === 0) {
if (integrityInfo.integrity && Object.keys(integrityInfo.integrity).length === 0) {
return reject(
new SecurityError(
this.config.reporter.lang('fetchBadIntegrityAlgorithm', this.packageName, this.remote.reference),
Expand Down Expand Up @@ -350,7 +352,7 @@ export default class TarballFetcher extends BaseFetcher {
return {integrity: null, algorithms};
}

const algorithms = new Set();
const algorithms = new Set(['sha512']);
const integrity = {};
for (const algorithm of expectedIntegrityAlgorithms) {
if (isHashAlgorithmSupported(algorithm)) {
Expand Down
7 changes: 5 additions & 2 deletions src/package-fetcher.js
Expand Up @@ -20,15 +20,18 @@ async function fetchCache(
// $FlowFixMe: This error doesn't make sense
const {hash, package: pkg, remote: cacheRemote} = await config.readPackageMetadata(dest);

const cacheIntegrity = cacheRemote.cacheIntegrity || cacheRemote.integrity;
const cacheHash = cacheRemote.hash;

if (remote.integrity) {
if (!cacheRemote.integrity || !ssri.parse(remote.integrity).match(cacheRemote.integrity)) {
if (!cacheIntegrity || !ssri.parse(cacheIntegrity).match(remote.integrity)) {
// eslint-disable-next-line yarn-internal/warn-language
throw new MessageError('Incorrect integrity when fetching from the cache');
}
}

if (remote.hash) {
if (!cacheRemote.hash || cacheRemote.hash !== remote.hash) {
if (!cacheHash || cacheHash !== remote.hash) {
// eslint-disable-next-line yarn-internal/warn-language
throw new MessageError('Incorrect integrity when fetching from the cache');
}
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Expand Up @@ -56,6 +56,7 @@ export type PackageRemote = {
resolved?: ?string,
hash: ?string,
integrity?: ?string,
cacheIntegrity?: ?string,
packageName?: string,
registryRemote?: ?PackageRemote,
};
Expand Down