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(rubygems): Restrict metadata cache to rubygems.org host #23307

Merged
Merged
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
24 changes: 14 additions & 10 deletions lib/modules/datasource/rubygems/metadata-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import hasha from 'hasha';
import { logger } from '../../../logger';
import * as packageCache from '../../../util/cache/package';
import type { Http } from '../../../util/http';
import { joinUrlParts } from '../../../util/url';
import { joinUrlParts, parseUrl } from '../../../util/url';
import type { ReleaseResult } from '../types';
import { GemMetadata, GemVersions } from './schema';

Expand Down Expand Up @@ -52,15 +52,19 @@ export class MetadataCache {
data.homepage = metadata.homepage;
}

const newCache: CacheRecord = { hash, data };
const ttlMinutes = 100 * 24 * 60;
const ttlRandomDelta = Math.floor(Math.random() * 10 * 24 * 60);
await packageCache.set(
cacheNs,
cacheKey,
newCache,
ttlMinutes + ttlRandomDelta
);
const registryHostname = parseUrl(registryUrl)?.hostname;
if (registryHostname === 'rubygems.org') {
const newCache: CacheRecord = { hash, data };
const ttlMinutes = 100 * 24 * 60;
const ttlRandomDelta = Math.floor(Math.random() * 10 * 24 * 60);
await packageCache.set(
cacheNs,
cacheKey,
newCache,
ttlMinutes + ttlRandomDelta
);
}

return data;
} catch (err) {
logger.debug({ err }, 'Rubygems: failed to fetch metadata');
Expand Down