renovate 44.171.0 → 44.171.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/instrumentation/reporting.js +5 -1
  2. package/dist/instrumentation/reporting.js.map +1 -1
  3. package/dist/modules/datasource/common.d.ts +4 -0
  4. package/dist/modules/datasource/common.js +16 -1
  5. package/dist/modules/datasource/common.js.map +1 -1
  6. package/dist/modules/datasource/crate/index.js +4 -1
  7. package/dist/modules/datasource/crate/index.js.map +1 -1
  8. package/dist/modules/datasource/custom/index.js +5 -1
  9. package/dist/modules/datasource/custom/index.js.map +1 -1
  10. package/dist/modules/datasource/custom/utils.js +2 -1
  11. package/dist/modules/datasource/custom/utils.js.map +1 -1
  12. package/dist/modules/datasource/docker/common.js +1 -1
  13. package/dist/modules/datasource/git-refs/base.js +2 -1
  14. package/dist/modules/datasource/git-refs/base.js.map +1 -1
  15. package/dist/modules/datasource/index.js +20 -10
  16. package/dist/modules/datasource/index.js.map +1 -1
  17. package/dist/modules/datasource/metadata.js +36 -9
  18. package/dist/modules/datasource/metadata.js.map +1 -1
  19. package/dist/modules/manager/bun/extract.js +7 -2
  20. package/dist/modules/manager/bun/extract.js.map +1 -1
  21. package/dist/modules/manager/fingerprint.generated.js +4 -4
  22. package/dist/modules/manager/fingerprint.generated.js.map +1 -1
  23. package/dist/modules/manager/npm/extract/index.js +3 -2
  24. package/dist/modules/manager/npm/extract/index.js.map +1 -1
  25. package/dist/modules/manager/npm/extract/post/monorepo.js +6 -3
  26. package/dist/modules/manager/npm/extract/post/monorepo.js.map +1 -1
  27. package/dist/modules/manager/npm/npmrc.js +162 -11
  28. package/dist/modules/manager/npm/npmrc.js.map +1 -1
  29. package/dist/modules/manager/npmrc.js +35 -0
  30. package/dist/modules/manager/npmrc.js.map +1 -0
  31. package/dist/modules/manager/pep621/processors/uv.js +9 -3
  32. package/dist/modules/manager/pep621/processors/uv.js.map +1 -1
  33. package/dist/modules/manager/pipenv/artifacts.js +16 -5
  34. package/dist/modules/manager/pipenv/artifacts.js.map +1 -1
  35. package/dist/util/cache/package/index.js +7 -4
  36. package/dist/util/cache/package/index.js.map +1 -1
  37. package/dist/util/cache/repository/http-cache.js +10 -0
  38. package/dist/util/cache/repository/http-cache.js.map +1 -1
  39. package/dist/util/cache/sanitize-key.js +63 -0
  40. package/dist/util/cache/sanitize-key.js.map +1 -0
  41. package/dist/util/git/auth.js +22 -2
  42. package/dist/util/git/auth.js.map +1 -1
  43. package/dist/util/git/index.d.ts +2 -0
  44. package/dist/util/git/index.js +1 -1
  45. package/dist/util/git/index.js.map +1 -1
  46. package/dist/util/host-rules.d.ts +33 -2
  47. package/dist/util/host-rules.js +237 -12
  48. package/dist/util/host-rules.js.map +1 -1
  49. package/dist/util/http/cache/abstract-http-cache-provider.js +17 -0
  50. package/dist/util/http/cache/abstract-http-cache-provider.js.map +1 -1
  51. package/dist/util/http/cache/memory-http-cache-provider.js +1 -0
  52. package/dist/util/http/cache/memory-http-cache-provider.js.map +1 -1
  53. package/dist/util/http/cache/persisted-headers.js +27 -0
  54. package/dist/util/http/cache/persisted-headers.js.map +1 -0
  55. package/dist/util/http/cache/repository-http-cache-provider.js +7 -4
  56. package/dist/util/http/cache/repository-http-cache-provider.js.map +1 -1
  57. package/dist/util/http/host-rules.js +2 -15
  58. package/dist/util/http/host-rules.js.map +1 -1
  59. package/dist/util/http/http.js +1 -1
  60. package/dist/util/jsonata.js +1 -1
  61. package/dist/util/merge-confidence/index.js +1 -1
  62. package/dist/util/url.d.ts +38 -0
  63. package/dist/util/url.js +100 -2
  64. package/dist/util/url.js.map +1 -1
  65. package/dist/workers/repository/cache.js +9 -1
  66. package/dist/workers/repository/cache.js.map +1 -1
  67. package/dist/workers/repository/init/merge.js +1 -1
  68. package/dist/workers/repository/init/merge.js.map +1 -1
  69. package/dist/workers/repository/onboarding/branch/rebase.js +1 -1
  70. package/dist/workers/repository/onboarding/pr/index.js +1 -1
  71. package/dist/workers/repository/process/extract-update.js +53 -5
  72. package/dist/workers/repository/process/extract-update.js.map +1 -1
  73. package/dist/workers/repository/process/fetch.js +2 -1
  74. package/dist/workers/repository/process/fetch.js.map +1 -1
  75. package/dist/workers/repository/process/lookup/digest.js +8 -4
  76. package/dist/workers/repository/process/lookup/digest.js.map +1 -1
  77. package/dist/workers/repository/process/lookup/index.js +13 -8
  78. package/dist/workers/repository/process/lookup/index.js.map +1 -1
  79. package/dist/workers/repository/update/branch/index.js +5 -3
  80. package/dist/workers/repository/update/branch/index.js.map +1 -1
  81. package/dist/workers/repository/updates/branch-name.js +5 -4
  82. package/dist/workers/repository/updates/branch-name.js.map +1 -1
  83. package/dist/workers/repository/updates/flatten.js +2 -2
  84. package/dist/workers/repository/updates/flatten.js.map +1 -1
  85. package/dist/workers/repository/updates/generate.js +5 -4
  86. package/dist/workers/repository/updates/generate.js.map +1 -1
  87. package/package.json +2 -2
  88. package/renovate-schema.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import { get, set } from "../../cache/memory/index.js";
2
+ import { hashUserinfoAndQuery } from "../../cache/sanitize-key.js";
2
3
  import { copyResponse } from "../util.js";
3
4
  import { getCache } from "../../cache/repository/index.js";
4
5
  import { AbstractHttpCacheProvider } from "./abstract-http-cache-provider.js";
@@ -11,22 +12,24 @@ var RepositoryHttpCacheProvider = class extends AbstractHttpCacheProvider {
11
12
  }
12
13
  load(method, url) {
13
14
  const cache = getCache();
15
+ const key = hashUserinfoAndQuery(url);
14
16
  if (method === "head") {
15
17
  cache.httpCacheHead ??= {};
16
- return Promise.resolve(cache.httpCacheHead[url]);
18
+ return Promise.resolve(cache.httpCacheHead[key]);
17
19
  }
18
20
  cache.httpCache ??= {};
19
- return Promise.resolve(cache.httpCache[url]);
21
+ return Promise.resolve(cache.httpCache[key]);
20
22
  }
21
23
  persist(method, url, data) {
22
24
  const cache = getCache();
25
+ const key = hashUserinfoAndQuery(url);
23
26
  if (method === "head") {
24
27
  cache.httpCacheHead ??= {};
25
- cache.httpCacheHead[url] = data;
28
+ cache.httpCacheHead[key] = data;
26
29
  return Promise.resolve();
27
30
  }
28
31
  cache.httpCache ??= {};
29
- cache.httpCache[url] = data;
32
+ cache.httpCache[key] = data;
30
33
  return Promise.resolve();
31
34
  }
32
35
  getSyncFlags() {
@@ -1 +1 @@
1
- {"version":3,"file":"repository-http-cache-provider.js","names":["memGet"],"sources":["../../../../lib/util/http/cache/repository-http-cache-provider.ts"],"sourcesContent":["import { get as memGet, set as memSet } from '../../cache/memory/index.ts';\nimport { getCache } from '../../cache/repository/index.ts';\nimport type { HttpResponse } from '../types.ts';\nimport { copyResponse } from '../util.ts';\nimport { AbstractHttpCacheProvider } from './abstract-http-cache-provider.ts';\nimport type { HttpCache } from './schema.ts';\n\nexport class RepositoryHttpCacheProvider extends AbstractHttpCacheProvider {\n private aggressive: boolean;\n\n constructor(aggressive = false) {\n super();\n this.aggressive = aggressive;\n }\n\n override load(method: string, url: string): Promise<unknown> {\n const cache = getCache();\n\n if (method === 'head') {\n cache.httpCacheHead ??= {};\n return Promise.resolve(cache.httpCacheHead[url]);\n }\n\n cache.httpCache ??= {};\n return Promise.resolve(cache.httpCache[url]);\n }\n\n override persist(\n method: string,\n url: string,\n data: HttpCache,\n ): Promise<void> {\n const cache = getCache();\n\n if (method === 'head') {\n cache.httpCacheHead ??= {};\n cache.httpCacheHead[url] = data;\n return Promise.resolve();\n }\n\n cache.httpCache ??= {};\n cache.httpCache[url] = data;\n return Promise.resolve();\n }\n\n private getSyncFlags(): Record<string, boolean> {\n let flags = memGet<Record<string, boolean>>('repo-cache-flags');\n if (!flags) {\n flags = {};\n memSet('repo-cache-flags', flags);\n }\n return flags;\n }\n\n private isSynced(method: string, url: string): boolean {\n if (!this.aggressive) {\n return false;\n }\n\n const flags = this.getSyncFlags();\n return !!flags[`${method}:${url}`];\n }\n\n markSynced(method: string, url: string, value = true): void {\n const flags = this.getSyncFlags();\n flags[`${method}:${url}`] = value;\n }\n\n override wrapServerResponse<T>(\n method: string,\n url: string,\n resp: HttpResponse<T>,\n ): Promise<HttpResponse<T>> {\n const res = super.wrapServerResponse(method, url, resp);\n this.markSynced(method, url);\n return res;\n }\n\n override async bypassServer<T>(\n method: string,\n url: string,\n _ignoreSoftTtl: boolean,\n ): Promise<HttpResponse<T> | null> {\n if (!this.isSynced(method, url)) {\n return null;\n }\n\n const httpCache = await this.get(method, url);\n if (!httpCache) {\n return null;\n }\n\n // Deep copy is needed because the underlying storage for repository cache is the plain object.\n // This object gets persisted at the end of the run.\n // However, during the run, we don't want to accidentally return the same response objects.\n return copyResponse(httpCache.httpResponse as HttpResponse<T>, true);\n }\n}\n\nexport const repoCacheProvider = new RepositoryHttpCacheProvider();\n\n/**\n * This is useful when you use `memCacheProvider`,\n * but want the values be persisted for longer time.\n */\nexport const aggressiveRepoCacheProvider = new RepositoryHttpCacheProvider(\n true,\n);\n"],"mappings":";;;;;AAOA,IAAa,8BAAb,cAAiD,0BAA0B;CACzE;CAEA,YAAY,aAAa,OAAO;EAC9B,MAAM;EACN,KAAK,aAAa;CACpB;CAEA,KAAc,QAAgB,KAA+B;EAC3D,MAAM,QAAQ,SAAS;EAEvB,IAAI,WAAW,QAAQ;GACrB,MAAM,kBAAkB,CAAC;GACzB,OAAO,QAAQ,QAAQ,MAAM,cAAc,IAAI;EACjD;EAEA,MAAM,cAAc,CAAC;EACrB,OAAO,QAAQ,QAAQ,MAAM,UAAU,IAAI;CAC7C;CAEA,QACE,QACA,KACA,MACe;EACf,MAAM,QAAQ,SAAS;EAEvB,IAAI,WAAW,QAAQ;GACrB,MAAM,kBAAkB,CAAC;GACzB,MAAM,cAAc,OAAO;GAC3B,OAAO,QAAQ,QAAQ;EACzB;EAEA,MAAM,cAAc,CAAC;EACrB,MAAM,UAAU,OAAO;EACvB,OAAO,QAAQ,QAAQ;CACzB;CAEA,eAAgD;EAC9C,IAAI,QAAQA,IAAgC,kBAAkB;EAC9D,IAAI,CAAC,OAAO;GACV,QAAQ,CAAC;GACT,IAAO,oBAAoB,KAAK;EAClC;EACA,OAAO;CACT;CAEA,SAAiB,QAAgB,KAAsB;EACrD,IAAI,CAAC,KAAK,YACR,OAAO;EAIT,OAAO,CAAC,CADM,KAAK,aACN,CAAC,CAAC,GAAG,OAAO,GAAG;CAC9B;CAEA,WAAW,QAAgB,KAAa,QAAQ,MAAY;EAC1D,MAAM,QAAQ,KAAK,aAAa;EAChC,MAAM,GAAG,OAAO,GAAG,SAAS;CAC9B;CAEA,mBACE,QACA,KACA,MAC0B;EAC1B,MAAM,MAAM,MAAM,mBAAmB,QAAQ,KAAK,IAAI;EACtD,KAAK,WAAW,QAAQ,GAAG;EAC3B,OAAO;CACT;CAEA,MAAe,aACb,QACA,KACA,gBACiC;EACjC,IAAI,CAAC,KAAK,SAAS,QAAQ,GAAG,GAC5B,OAAO;EAGT,MAAM,YAAY,MAAM,KAAK,IAAI,QAAQ,GAAG;EAC5C,IAAI,CAAC,WACH,OAAO;EAMT,OAAO,aAAa,UAAU,cAAiC,IAAI;CACrE;AACF;AAEA,MAAa,oBAAoB,IAAI,4BAA4B;;;;;AAMjE,MAAa,8BAA8B,IAAI,4BAC7C,IACF"}
1
+ {"version":3,"file":"repository-http-cache-provider.js","names":["memGet"],"sources":["../../../../lib/util/http/cache/repository-http-cache-provider.ts"],"sourcesContent":["import { get as memGet, set as memSet } from '../../cache/memory/index.ts';\nimport { getCache } from '../../cache/repository/index.ts';\nimport { hashUserinfoAndQuery } from '../../cache/sanitize-key.ts';\nimport type { HttpResponse } from '../types.ts';\nimport { copyResponse } from '../util.ts';\nimport { AbstractHttpCacheProvider } from './abstract-http-cache-provider.ts';\nimport type { HttpCache } from './schema.ts';\n\nexport class RepositoryHttpCacheProvider extends AbstractHttpCacheProvider {\n private aggressive: boolean;\n\n constructor(aggressive = false) {\n super();\n this.aggressive = aggressive;\n }\n\n override load(method: string, url: string): Promise<unknown> {\n const cache = getCache();\n const key = hashUserinfoAndQuery(url);\n\n if (method === 'head') {\n cache.httpCacheHead ??= {};\n return Promise.resolve(cache.httpCacheHead[key]);\n }\n\n cache.httpCache ??= {};\n return Promise.resolve(cache.httpCache[key]);\n }\n\n override persist(\n method: string,\n url: string,\n data: HttpCache,\n ): Promise<void> {\n const cache = getCache();\n const key = hashUserinfoAndQuery(url);\n\n if (method === 'head') {\n cache.httpCacheHead ??= {};\n cache.httpCacheHead[key] = data;\n return Promise.resolve();\n }\n\n cache.httpCache ??= {};\n cache.httpCache[key] = data;\n return Promise.resolve();\n }\n\n private getSyncFlags(): Record<string, boolean> {\n let flags = memGet<Record<string, boolean>>('repo-cache-flags');\n if (!flags) {\n flags = {};\n memSet('repo-cache-flags', flags);\n }\n return flags;\n }\n\n private isSynced(method: string, url: string): boolean {\n if (!this.aggressive) {\n return false;\n }\n\n const flags = this.getSyncFlags();\n return !!flags[`${method}:${url}`];\n }\n\n markSynced(method: string, url: string, value = true): void {\n const flags = this.getSyncFlags();\n flags[`${method}:${url}`] = value;\n }\n\n override wrapServerResponse<T>(\n method: string,\n url: string,\n resp: HttpResponse<T>,\n ): Promise<HttpResponse<T>> {\n const res = super.wrapServerResponse(method, url, resp);\n this.markSynced(method, url);\n return res;\n }\n\n override async bypassServer<T>(\n method: string,\n url: string,\n _ignoreSoftTtl: boolean,\n ): Promise<HttpResponse<T> | null> {\n if (!this.isSynced(method, url)) {\n return null;\n }\n\n const httpCache = await this.get(method, url);\n if (!httpCache) {\n return null;\n }\n\n // Deep copy is needed because the underlying storage for repository cache is the plain object.\n // This object gets persisted at the end of the run.\n // However, during the run, we don't want to accidentally return the same response objects.\n return copyResponse(httpCache.httpResponse as HttpResponse<T>, true);\n }\n}\n\nexport const repoCacheProvider = new RepositoryHttpCacheProvider();\n\n/**\n * This is useful when you use `memCacheProvider`,\n * but want the values be persisted for longer time.\n */\nexport const aggressiveRepoCacheProvider = new RepositoryHttpCacheProvider(\n true,\n);\n"],"mappings":";;;;;;AAQA,IAAa,8BAAb,cAAiD,0BAA0B;CACzE;CAEA,YA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I,QAAQ,GAAG;EAC5C,IAAI,CAAC,WACH,OAAO;EAMT,OAAO,aAAa,UAAU,cAAiC,IAAI;CACrE;AACF;AAEA,MAAa,oBAAoB,IAAI,4BAA4B;;;;;AAMjE,MAAa,8BAA8B,IAAI,4BAC7C,IACF"}
@@ -3,7 +3,7 @@ import { matchRegexOrGlobList } from "../string-match.js";
3
3
  import { logger } from "../../logger/index.js";
4
4
  import { PLATFORM_FAMILIES } from "../../constants/platforms.js";
5
5
  import { parseUrl } from "../url.js";
6
- import { find } from "../host-rules.js";
6
+ import { find, usesGithubUrlFallback } from "../host-rules.js";
7
7
  import { hasProxy } from "../../proxy.js";
8
8
  import { keepAliveAgents } from "./keep-alive.js";
9
9
  import { isNonEmptyString } from "@sindresorhus/is";
@@ -23,26 +23,13 @@ function findMatchingRule(url, options) {
23
23
  }),
24
24
  ...res
25
25
  };
26
- const platform = GlobalConfig.get("platform");
27
- const platformEndpoint = GlobalConfig.get("endpoint");
28
- if (url.startsWith("https://api.github.com/")) res = {
26
+ if (usesGithubUrlFallback(url)) res = {
29
27
  ...find({
30
28
  hostType: "github",
31
29
  url
32
30
  }),
33
31
  ...res
34
32
  };
35
- else if (platform === "github" && platformEndpoint) {
36
- const requestHost = parseUrl(url)?.hostname;
37
- const endpointHost = parseUrl(platformEndpoint)?.hostname;
38
- if (requestHost && endpointHost && requestHost === endpointHost) res = {
39
- ...find({
40
- hostType: "github",
41
- url
42
- }),
43
- ...res
44
- };
45
- }
46
33
  if (hostType && PLATFORM_FAMILIES.gitlab.apiUsingHostTypes.includes(hostType) && hostType !== "gitlab") res = {
47
34
  ...find({
48
35
  hostType: "gitlab",
@@ -1 +1 @@
1
- {"version":3,"file":"host-rules.js","names":["hostRules.find"],"sources":["../../../lib/util/http/host-rules.ts"],"sourcesContent":["import { isNonEmptyString } from '@sindresorhus/is';\nimport { GlobalConfig } from '../../config/global.ts';\nimport { PLATFORM_FAMILIES } from '../../constants/index.ts';\nimport { logger } from '../../logger/index.ts';\nimport { hasProxy } from '../../proxy.ts';\nimport type { CombinedHostRuleWithTrustedHeaders } from '../host-rules.ts';\nimport * as hostRules from '../host-rules.ts';\nimport { matchRegexOrGlobList } from '../string-match.ts';\nimport { parseUrl } from '../url.ts';\nimport type { InternalHttpOptions } from './http.ts';\nimport { keepAliveAgents } from './keep-alive.ts';\nimport type { GotOptions } from './types.ts';\n\nexport type HostRulesGotOptions = Pick<\n GotOptions & InternalHttpOptions,\n | 'hostType'\n | 'noAuth'\n | 'headers'\n | 'token'\n | 'username'\n | 'password'\n | 'context'\n | 'enabled'\n | 'abortOnError'\n | 'abortIgnoreStatusCodes'\n | 'timeout'\n | 'agent'\n | 'http2'\n | 'https'\n | 'readOnly'\n>;\n\nexport function findMatchingRule<GotOptions extends HostRulesGotOptions>(\n url: string,\n options: GotOptions,\n): CombinedHostRuleWithTrustedHeaders {\n const { hostType, readOnly } = options;\n let res = hostRules.find({ hostType, url, readOnly });\n\n if (\n isNonEmptyString(res.token) ||\n isNonEmptyString(res.username) ||\n isNonEmptyString(res.password)\n ) {\n // do not fallback if we already have auth infos\n return res;\n }\n\n // Fallback to `github` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.github.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'github'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'github',\n url,\n }),\n ...res,\n };\n }\n\n const platform = GlobalConfig.get('platform');\n const platformEndpoint = GlobalConfig.get('endpoint');\n\n // in the case that an API URL is used for GitHub.com, fallback to `github` hostType, and use the `url`'s host to find a `matchHost: api.github.com` (or `matchHost: github.com`)\n if (url.startsWith('https://api.github.com/')) {\n res = {\n ...hostRules.find({\n hostType: 'github',\n url,\n }),\n ...res,\n };\n } else if (platform === 'github' && platformEndpoint) {\n // Fallback to `github` hostType when the request URL targets the same host\n // as the configured GitHub platform endpoint.\n //\n // This covers GitHub Enterprise Server without hardcoding URLs.\n const requestHost = parseUrl(url)?.hostname;\n const endpointHost = parseUrl(platformEndpoint)?.hostname;\n if (requestHost && endpointHost && requestHost === endpointHost) {\n res = {\n ...hostRules.find({ hostType: 'github', url }),\n ...res,\n };\n }\n }\n\n // Fallback to `gitlab` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.gitlab.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'gitlab'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'gitlab',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `bitbucket` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.bitbucket.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'bitbucket'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'bitbucket',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `bitbucket-server` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES['bitbucket-server'].apiUsingHostTypes.includes(\n hostType,\n ) &&\n hostType !== 'bitbucket-server'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'bitbucket-server',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `forgejo` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.forgejo.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'forgejo'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'forgejo',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `gitea` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.gitea.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'gitea'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'gitea',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `go` hostType, which requests to a Go module proxy used until they were split into the `go-proxy` datasource\n if (hostType === 'go-proxy') {\n // only inherit the authentication-related fields\n const {\n token,\n authType,\n username,\n password,\n httpsCertificate,\n httpsPrivateKey,\n httpsCertificateAuthority,\n } = hostRules.find({ hostType: 'go', url });\n res = {\n token,\n authType,\n username,\n password,\n httpsCertificate,\n httpsPrivateKey,\n httpsCertificateAuthority,\n ...res,\n };\n }\n\n return res;\n}\n\n// Apply host rules to requests\nexport function applyHostRule<GotOptions extends HostRulesGotOptions>(\n url: string,\n options: GotOptions,\n hostRule: CombinedHostRuleWithTrustedHeaders,\n): GotOptions {\n if (hostRule.enabled === false) {\n options.enabled = false;\n return options;\n }\n\n const { username, password, token, authType } = hostRule;\n const host = parseUrl(url)?.host;\n if (options.noAuth) {\n logger.trace({ url }, `Authorization disabled`);\n } else if (\n isNonEmptyString(options.headers?.authorization) ||\n isNonEmptyString(options.password) ||\n isNonEmptyString(options.token)\n ) {\n logger.once.debug(`hostRules: authentication already set for ${host}`);\n logger.trace({ url }, `Authorization already set`);\n } else if (password !== undefined) {\n logger.once.debug(`hostRules: applying Basic authentication for ${host}`);\n logger.trace({ url }, `Applying Basic authentication`);\n options.username = username;\n options.password = password;\n } else if (token) {\n logger.once.debug(`hostRules: applying Bearer authentication for ${host}`);\n logger.trace({ url }, `Applying Bearer authentication`);\n options.token = token;\n options.context = { ...options.context, authType };\n } else {\n logger.once.debug(`hostRules: no authentication for ${host}`);\n }\n // Apply optional params\n if (hostRule.abortOnError) {\n options.abortOnError = hostRule.abortOnError;\n }\n\n if (hostRule.abortIgnoreStatusCodes) {\n options.abortIgnoreStatusCodes = hostRule.abortIgnoreStatusCodes;\n }\n\n if (hostRule.timeout) {\n options.timeout = hostRule.timeout;\n }\n\n if (hostRule.headers) {\n const allowedHeaders = GlobalConfig.get('allowedHeaders');\n // headers already known to have come from the self-hosted administrator's own (`trusted`) config bypassed `allowedHeaders` at registration - see `hostRules.add()` - so must not be re-checked, and dropped, here\n const trustedHeaderNames = new Set(hostRule.trustedHeaderNames);\n const filteredHeaders: Record<string, string> = {};\n\n for (const [header, value] of Object.entries(hostRule.headers)) {\n if (\n trustedHeaderNames.has(header) ||\n matchRegexOrGlobList(header, allowedHeaders)\n ) {\n filteredHeaders[header] = value;\n } else {\n logger.once.error(\n { allowedHeaders, header },\n 'Disallowed hostRules headers',\n );\n }\n }\n\n options.headers = {\n ...options.headers,\n ...filteredHeaders,\n };\n }\n\n if (hostRule.keepAlive) {\n options.agent = keepAliveAgents;\n }\n\n if (!hasProxy() && hostRule.enableHttp2 === true) {\n options.http2 = true;\n }\n\n if (isNonEmptyString(hostRule.httpsCertificateAuthority)) {\n options.https = {\n ...options.https,\n certificateAuthority: hostRule.httpsCertificateAuthority,\n };\n }\n\n if (isNonEmptyString(hostRule.httpsPrivateKey)) {\n options.https = {\n ...options.https,\n key: hostRule.httpsPrivateKey,\n };\n }\n\n if (isNonEmptyString(hostRule.httpsCertificate)) {\n options.https = {\n ...options.https,\n certificate: hostRule.httpsCertificate,\n };\n }\n\n return options;\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,iBACd,KACA,SACoC;CACpC,MAAM,EAAE,UAAU,aAAa;CAC/B,IAAI,MAAMA,KAAe;EAAE;EAAU;EAAK;CAAS,CAAC;CAEpD,IACE,iBAAiB,IAAI,KAAK,KAC1B,iBAAiB,IAAI,QAAQ,KAC7B,iBAAiB,IAAI,QAAQ,GAG7B,OAAO;CAIT,IACE,YACA,kBAAkB,OAAO,kBAAkB,SAAS,QAAQ,KAC5D,aAAa,UAEb,MAAM;EACJ,GAAGA,KAAe;GAChB,UAAU;GACV;EACF,CAAC;EACD,GAAG;CACL;CAGF,MAAM,WAAW,aAAa,IAAI,UAAU;CAC5C,MAAM,mBAAmB,aAAa,IAAI,UAAU;CAGpD,IAAI,IAAI,WAAW,yBAAyB,GAC1C,MAAM;EACJ,GAAGA,KAAe;GAChB,UAAU;GACV;EACF,CAAC;EACD,GAAG;CACL;MACK,IAAI,aAAa,YAAY,kBAAkB;EAKpD,MAAM,cAAc,SAAS,GAAG,CAAC,EAAE;EACnC,MAAM,eAAe,SAAS,gBAAgB,CAAC,EAAE;EACjD,IAAI,eAAe,gBAAgB,gBAAgB,cACjD,MAAM;GACJ,GAAGA,KAAe;IAAE,UAAU;IAAU;GAAI,CAAC;GAC7C,GAAG;EACL;CAEJ;CAGA,IACE,YACA,kBAAkB,OAAO,kBAAk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QAAQ,QAAQ;EACd,GAAG,QAAQ;EACX,KAAK,SAAS;CAChB;CAGF,IAAI,iBAAiB,SAAS,gBAAgB,GAC5C,QAAQ,QAAQ;EACd,GAAG,QAAQ;EACX,aAAa,SAAS;CACxB;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"host-rules.js","names":["hostRules.find","hostRules.usesGithubUrlFallback"],"sources":["../../../lib/util/http/host-rules.ts"],"sourcesContent":["import { isNonEmptyString } from '@sindresorhus/is';\nimport { GlobalConfig } from '../../config/global.ts';\nimport { PLATFORM_FAMILIES } from '../../constants/index.ts';\nimport { logger } from '../../logger/index.ts';\nimport { hasProxy } from '../../proxy.ts';\nimport type { CombinedHostRuleWithTrustedHeaders } from '../host-rules.ts';\nimport * as hostRules from '../host-rules.ts';\nimport { matchRegexOrGlobList } from '../string-match.ts';\nimport { parseUrl } from '../url.ts';\nimport type { InternalHttpOptions } from './http.ts';\nimport { keepAliveAgents } from './keep-alive.ts';\nimport type { GotOptions } from './types.ts';\n\nexport type HostRulesGotOptions = Pick<\n GotOptions & InternalHttpOptions,\n | 'hostType'\n | 'noAuth'\n | 'headers'\n | 'token'\n | 'username'\n | 'password'\n | 'context'\n | 'enabled'\n | 'abortOnError'\n | 'abortIgnoreStatusCodes'\n | 'timeout'\n | 'agent'\n | 'http2'\n | 'https'\n | 'readOnly'\n>;\n\nexport function findMatchingRule<GotOptions extends HostRulesGotOptions>(\n url: string,\n options: GotOptions,\n): CombinedHostRuleWithTrustedHeaders {\n const { hostType, readOnly } = options;\n let res = hostRules.find({ hostType, url, readOnly });\n\n if (\n isNonEmptyString(res.token) ||\n isNonEmptyString(res.username) ||\n isNonEmptyString(res.password)\n ) {\n // do not fallback if we already have auth infos\n return res;\n }\n\n // Fallback to `github` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.github.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'github'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'github',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `github` hostType for the GitHub.com API and the host of the GitHub platform endpoint, such as GitHub Enterprise Server or GitHub Enterprise Cloud\n if (hostRules.usesGithubUrlFallback(url)) {\n res = {\n ...hostRules.find({ hostType: 'github', url }),\n ...res,\n };\n }\n\n // Fallback to `gitlab` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.gitlab.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'gitlab'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'gitlab',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `bitbucket` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.bitbucket.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'bitbucket'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'bitbucket',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `bitbucket-server` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES['bitbucket-server'].apiUsingHostTypes.includes(\n hostType,\n ) &&\n hostType !== 'bitbucket-server'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'bitbucket-server',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `forgejo` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.forgejo.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'forgejo'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'forgejo',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `gitea` hostType\n if (\n hostType &&\n PLATFORM_FAMILIES.gitea.apiUsingHostTypes.includes(hostType) &&\n hostType !== 'gitea'\n ) {\n res = {\n ...hostRules.find({\n hostType: 'gitea',\n url,\n }),\n ...res,\n };\n }\n\n // Fallback to `go` hostType, which requests to a Go module proxy used until they were split into the `go-proxy` datasource\n if (hostType === 'go-proxy') {\n // only inherit the authentication-related fields\n const {\n token,\n authType,\n username,\n password,\n httpsCertificate,\n httpsPrivateKey,\n httpsCertificateAuthority,\n } = hostRules.find({ hostType: 'go', url });\n res = {\n token,\n authType,\n username,\n password,\n httpsCertificate,\n httpsPrivateKey,\n httpsCertificateAuthority,\n ...res,\n };\n }\n\n return res;\n}\n\n// Apply host rules to requests\nexport function applyHostRule<GotOptions extends HostRulesGotOptions>(\n url: string,\n options: GotOptions,\n hostRule: CombinedHostRuleWithTrustedHeaders,\n): GotOptions {\n if (hostRule.enabled === false) {\n options.enabled = false;\n return options;\n }\n\n const { username, password, token, authType } = hostRule;\n const host = parseUrl(url)?.host;\n if (options.noAuth) {\n logger.trace({ url }, `Authorization disabled`);\n } else if (\n isNonEmptyString(options.headers?.authorization) ||\n isNonEmptyString(options.password) ||\n isNonEmptyString(options.token)\n ) {\n logger.once.debug(`hostRules: authentication already set for ${host}`);\n logger.trace({ url }, `Authorization already set`);\n } else if (password !== undefined) {\n logger.once.debug(`hostRules: applying Basic authentication for ${host}`);\n logger.trace({ url }, `Applying Basic authentication`);\n options.username = username;\n options.password = password;\n } else if (token) {\n logger.once.debug(`hostRules: applying Bearer authentication for ${host}`);\n logger.trace({ url }, `Applying Bearer authentication`);\n options.token = token;\n options.context = { ...options.context, authType };\n } else {\n logger.once.debug(`hostRules: no authentication for ${host}`);\n }\n // Apply optional params\n if (hostRule.abortOnError) {\n options.abortOnError = hostRule.abortOnError;\n }\n\n if (hostRule.abortIgnoreStatusCodes) {\n options.abortIgnoreStatusCodes = hostRule.abortIgnoreStatusCodes;\n }\n\n if (hostRule.timeout) {\n options.timeout = hostRule.timeout;\n }\n\n if (hostRule.headers) {\n const allowedHeaders = GlobalConfig.get('allowedHeaders');\n // headers already known to have come from the self-hosted administrator's own (`trusted`) config bypassed `allowedHeaders` at registration - see `hostRules.add()` - so must not be re-checked, and dropped, here\n const trustedHeaderNames = new Set(hostRule.trustedHeaderNames);\n const filteredHeaders: Record<string, string> = {};\n\n for (const [header, value] of Object.entries(hostRule.headers)) {\n if (\n trustedHeaderNames.has(header) ||\n matchRegexOrGlobList(header, allowedHeaders)\n ) {\n filteredHeaders[header] = value;\n } else {\n logger.once.error(\n { allowedHeaders, header },\n 'Disallowed hostRules headers',\n );\n }\n }\n\n options.headers = {\n ...options.headers,\n ...filteredHeaders,\n };\n }\n\n if (hostRule.keepAlive) {\n options.agent = keepAliveAgents;\n }\n\n if (!hasProxy() && hostRule.enableHttp2 === true) {\n options.http2 = true;\n }\n\n if (isNonEmptyString(hostRule.httpsCertificateAuthority)) {\n options.https = {\n ...options.https,\n certificateAuthority: hostRule.httpsCertificateAuthority,\n };\n }\n\n if (isNonEmptyString(hostRule.httpsPrivateKey)) {\n options.https = {\n ...options.https,\n key: hostRule.httpsPrivateKey,\n };\n }\n\n if (isNonEmptyString(hostRule.httpsCertificate)) {\n options.https = {\n ...options.https,\n certificate: hostRule.httpsCertificate,\n };\n }\n\n return options;\n}\n"],"mappings":";;;;;;;;;;AAgCA,SAAgB,iBACd,KACA,SACoC;CACpC,MAAM,EAAE,UAAU,aAAa;CAC/B,IAAI,MAAMA,KAAe;EAAE;EAAU;EAAK;CAAS,CAAC;CAEpD,IACE,iBAAiB,IAAI,KAAK,KAC1B,iBAAiB,IAAI,QAAQ,KAC7B,iBAAiB,IAAI,QAAQ,GAG7B,OAAO;CAIT,IACE,YACA,kBAAkB,OAAO,kBAAkB,SAAS,QAAQ,KAC5D,aAAa,UAEb,MAAM;EACJ,GAAGA,KAAe;GAChB,UAAU;GACV;EACF,CAAC;EACD,GAAG;CACL;CAIF,IAAIC,sBAAgC,GAAG,GACrC,MAAM;EACJ,GAAGD,KAAe;GAAE,UAAU;GAAU;EAAI,CAAC;EAC7C,GAAG;CACL;CAIF,IACE,YACA,kBAAkB,OAAO,kBAAkB,SAAS,QAAQ,KAC5D,aAAa,UAEb,MAAM;EACJ,GAAGA,KAAe;GAChB,UAAU;GACV;EACF,CAAC;EACD,GAAG;CACL;CAIF,IACE,YACA,kBAAkB,UAAU,kBAAkB,SAAS,QAAQ,KAC/D,aAAa,aAEb,MAAM;EACJ,GAAGA,KAAe;GAChB,UAAU;GACV;EACF,CAAC;EACD,GAAG;CACL;CAIF,I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Url, parseUrl, resolveBaseUrl } from "../url.js";
9
9
  import { ObsoleteCacheHitLogger } from "../stats.js";
10
+ import { hash } from "../hash.js";
10
11
  import { parseSingleYaml } from "../yaml.js";
11
12
  import { compile } from "../template/index.js";
12
- import { hash } from "../hash.js";
13
13
  import { ExternalHostError } from "../../types/errors/external-host-error.js";
14
14
  import { Toml } from "../schema-utils/index.js";
15
15
  import { fetch, normalize, stream } from "./got.js";
@@ -1,8 +1,8 @@
1
1
  import { get, set } from "./cache/memory/index.js";
2
2
  import { anyMatchRegexOrGlobList, matchRegexOrGlobList } from "./string-match.js";
3
3
  import { buildCacheKey } from "./cache/package/key.js";
4
- import { detectPlatform } from "./common.js";
5
4
  import { toSha256 } from "./hash.js";
5
+ import { detectPlatform } from "./common.js";
6
6
  import { isArray, isNonEmptyArray, isString } from "@sindresorhus/is";
7
7
  import jsonata from "jsonata";
8
8
  //#region lib/util/jsonata.ts
@@ -5,8 +5,8 @@ import { supportedDatasources as supportedDatasources$1 } from "../../config/pre
5
5
  import { ensureTrailingSlash, joinUrlParts, parseUrl } from "../url.js";
6
6
  import { ATTR_RENOVATE_DATASOURCE, ATTR_RENOVATE_PACKAGE_NAME } from "../../instrumentation/types.js";
7
7
  import { instrument } from "../../instrumentation/index.js";
8
- import { find } from "../host-rules.js";
9
8
  import { toSha256 } from "../hash.js";
9
+ import { find } from "../host-rules.js";
10
10
  import { ExternalHostError } from "../../types/errors/external-host-error.js";
11
11
  import { get, set } from "../cache/package/index.js";
12
12
  import { Http } from "../http/index.js";
@@ -54,6 +54,44 @@ export declare function createURLFromHostOrURL(url: string): URL | null;
54
54
  */
55
55
  export declare function stripUrlCredentials(url: URL): string;
56
56
  export declare function stripUrlCredentials(url: string | URL): string | null;
57
+ /**
58
+ * Matches the `scheme` and the `userinfo` of every URL inside a text, the userinfo ending at the last `@` before the path as in the URL standard.
59
+ *
60
+ * The text may not be a single URL but may contain several, e.g. a `replaceString`, a `managerData` value or a cache key, so we cannot perform URL parsing as-is
61
+ *
62
+ * A single URL is handled by {@link stripUrlCredentials} instead.
63
+ */
64
+ export declare const urlUserinfoRegex: RegExp;
65
+ /**
66
+ * Whether `username` is a placeholder username such as `oauth2accesstoken`.
67
+ */
68
+ export declare function isPlaceholderUsername(username: string): boolean;
69
+ /**
70
+ * Decodes a percent-encoded userinfo part, or returns it as is when it is not valid percent-encoding.
71
+ */
72
+ export declare function decodeUserinfo(value: string): string;
73
+ /**
74
+ * Whether a percent-encoded userinfo part, once decoded, is exactly one `${NAME}`, `${env.NAME}`, `${NAME:?msg}`, `${NAME?msg}`, upper-case `$NAME`, `${{ expression }}` or `{{ NAME }}` placeholder.
75
+ */
76
+ export declare function isUserinfoPlaceholder(value: string): boolean;
77
+ /**
78
+ * Whether a `scheme://userinfo@` followed by `rest` holds a credential once its parts are decoded:
79
+ * a non-empty password other than a template placeholder, or a username of at least {@link minUsernameCredentialLength} characters with an empty or no password, except for an ssh scheme, a template placeholder, a placeholder username or a username equal to the first path segment.
80
+ * A `docker://image:tag@digest` reference holds none.
81
+ */
82
+ export declare function isCredentialUserinfo(scheme: string, userinfo: string, rest: string): boolean;
83
+ /**
84
+ * Whether `text` contains a URL with a `user:password@` or `token@` userinfo.
85
+ */
86
+ export declare function hasUrlCredentials(text: string): boolean;
87
+ /**
88
+ * Whether any string inside `value`, searched through arrays and object values, contains a URL with credentials.
89
+ */
90
+ export declare function containsUrlCredentials(value: unknown): boolean;
91
+ /**
92
+ * Removes the `user:password@` or `token@` userinfo of every URL inside `text` that carries a credential, leaving the rest of `text` unchanged.
93
+ */
94
+ export declare function withoutUrlCredentials(text: string): string;
57
95
  export type LinkHeaderLinks = _parseLinkHeader.Links;
58
96
  export declare function parseLinkHeader(linkHeader: string | null | undefined): LinkHeaderLinks | null;
59
97
  /**
package/dist/util/url.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { regEx } from "./regex.js";
2
2
  import { logger } from "../logger/index.js";
3
- import { isArray, isNonEmptyString, isString, isUrlInstance } from "@sindresorhus/is";
3
+ import { isArray, isNonEmptyString, isObject, isString, isUrlInstance } from "@sindresorhus/is";
4
4
  import _parseLinkHeader from "parse-link-header";
5
5
  import urlJoin from "url-join";
6
6
  //#region lib/util/url.ts
@@ -120,6 +120,104 @@ function stripUrlCredentials(url) {
120
120
  stripped.password = "";
121
121
  return stripped.href;
122
122
  }
123
+ /**
124
+ * Matches the `scheme` and the `userinfo` of every URL inside a text, the userinfo ending at the last `@` before the path as in the URL standard.
125
+ *
126
+ * The text may not be a single URL but may contain several, e.g. a `replaceString`, a `managerData` value or a cache key, so we cannot perform URL parsing as-is
127
+ *
128
+ * A single URL is handled by {@link stripUrlCredentials} instead.
129
+ */
130
+ const urlUserinfoRegex = regEx(/(?<scheme>[a-z][a-z\d+.-]*):\/\/(?<userinfo>[^/?#\s]+)@/gi);
131
+ /**
132
+ * Matches exactly one `${NAME}`, `${env.NAME}`, `${NAME:?msg}`, `${NAME?msg}`, upper-case `$NAME`, `${{ expression }}` or `{{ NAME }}` reference.
133
+ */
134
+ const userinfoPlaceholderRegex = regEx(/^(?:\$\{(?:env\.)?[A-Za-z_]\w*(?::?\?[^{}]*)?\}|\$[A-Z_][A-Z\d_]*|\$\{\{\s*[^{}\s][^{}]*\}\}|\{\{\s*[A-Za-z_]\w*\s*\}\})$/);
135
+ /**
136
+ * Usernames without a password of their own, which stand for a credential resolved at request time.
137
+ *
138
+ * `oauth2accesstoken` is Google Artifact Registry's, whose token the pypi and docker datasources fetch per request.
139
+ *
140
+ * @see https://docs.renovatebot.com/docker/#google-container-registry-google-artifact-registry
141
+ */
142
+ const placeholderUsernames = /* @__PURE__ */ new Set(["oauth2accesstoken"]);
143
+ /**
144
+ * Whether `username` is a placeholder username such as `oauth2accesstoken`.
145
+ */
146
+ function isPlaceholderUsername(username) {
147
+ return placeholderUsernames.has(username);
148
+ }
149
+ /**
150
+ * Decodes a percent-encoded userinfo part, or returns it as is when it is not valid percent-encoding.
151
+ */
152
+ function decodeUserinfo(value) {
153
+ try {
154
+ return decodeURIComponent(value);
155
+ } catch {
156
+ return value;
157
+ }
158
+ }
159
+ /**
160
+ * Whether a percent-encoded userinfo part, once decoded, is exactly one `${NAME}`, `${env.NAME}`, `${NAME:?msg}`, `${NAME?msg}`, upper-case `$NAME`, `${{ expression }}` or `{{ NAME }}` placeholder.
161
+ */
162
+ function isUserinfoPlaceholder(value) {
163
+ return userinfoPlaceholderRegex.test(decodeUserinfo(value));
164
+ }
165
+ const firstPathSegmentRegex = regEx(/^[^/?#\s]*\/(?<segment>[^/?#\s]*)/);
166
+ /**
167
+ * Whether `username` equals, ignoring case, the first path segment of `rest`, the text following the `@` of a URL's userinfo.
168
+ */
169
+ function isFirstPathSegment(username, rest) {
170
+ const match = firstPathSegmentRegex.exec(rest);
171
+ if (!match) return false;
172
+ const { segment } = match.groups;
173
+ return decodeUserinfo(segment).toLowerCase() === username.toLowerCase();
174
+ }
175
+ /**
176
+ * The minimum length of a username without a password which counts as a credential.
177
+ */
178
+ const minUsernameCredentialLength = 16;
179
+ /**
180
+ * Whether a `scheme://userinfo@` followed by `rest` holds a credential once its parts are decoded:
181
+ * a non-empty password other than a template placeholder, or a username of at least {@link minUsernameCredentialLength} characters with an empty or no password, except for an ssh scheme, a template placeholder, a placeholder username or a username equal to the first path segment.
182
+ * A `docker://image:tag@digest` reference holds none.
183
+ */
184
+ function isCredentialUserinfo(scheme, userinfo, rest) {
185
+ const lowerScheme = scheme.toLowerCase();
186
+ if (lowerScheme === "docker") return false;
187
+ const [rawUsername, ...rawPasswordParts] = userinfo.split(":");
188
+ const rawPassword = rawPasswordParts.join(":");
189
+ if (rawPassword) return !isUserinfoPlaceholder(rawPassword);
190
+ const username = decodeUserinfo(rawUsername);
191
+ return username.length >= minUsernameCredentialLength && !lowerScheme.endsWith("ssh") && !isUserinfoPlaceholder(rawUsername) && !isPlaceholderUsername(username) && !isFirstPathSegment(username, rest);
192
+ }
193
+ /**
194
+ * Whether `text` contains a URL with a `user:password@` or `token@` userinfo.
195
+ */
196
+ function hasUrlCredentials(text) {
197
+ for (const match of text.matchAll(urlUserinfoRegex)) {
198
+ const { scheme, userinfo } = match.groups;
199
+ if (isCredentialUserinfo(scheme, userinfo, text.slice(match.index + match[0].length))) return true;
200
+ }
201
+ return false;
202
+ }
203
+ /**
204
+ * Whether any string inside `value`, searched through arrays and object values, contains a URL with credentials.
205
+ */
206
+ function containsUrlCredentials(value) {
207
+ if (isString(value)) return hasUrlCredentials(value);
208
+ if (isObject(value)) return Object.values(value).some(containsUrlCredentials);
209
+ return false;
210
+ }
211
+ /**
212
+ * Removes the `user:password@` or `token@` userinfo of every URL inside `text` that carries a credential, leaving the rest of `text` unchanged.
213
+ */
214
+ function withoutUrlCredentials(text) {
215
+ return text.replace(urlUserinfoRegex, (match, ...args) => {
216
+ const offset = args.at(-3);
217
+ const { scheme, userinfo } = args.at(-1);
218
+ return isCredentialUserinfo(scheme, userinfo, text.slice(offset + match.length)) ? `${scheme}://` : match;
219
+ });
220
+ }
123
221
  function parseLinkHeader(linkHeader) {
124
222
  if (!isNonEmptyString(linkHeader)) return null;
125
223
  if (linkHeader.length > 2e3) {
@@ -137,6 +235,6 @@ function massageHostUrl(url) {
137
235
  return url;
138
236
  }
139
237
  //#endregion
140
- export { createURLFromHostOrURL, ensurePathPrefix, ensureTrailingSlash, getQueryString, isHttpUrl, joinUrlParts, massageHostUrl, parseLinkHeader, parseUrl, replaceUrlPath, resolveBaseUrl, resolveSameOriginUrl, stripUrlCredentials, trimLeadingSlash, trimSlashes, trimTrailingSlash };
238
+ export { containsUrlCredentials, createURLFromHostOrURL, decodeUserinfo, ensurePathPrefix, ensureTrailingSlash, getQueryString, hasUrlCredentials, isCredentialUserinfo, isHttpUrl, isPlaceholderUsername, isUserinfoPlaceholder, joinUrlParts, massageHostUrl, parseLinkHeader, parseUrl, replaceUrlPath, resolveBaseUrl, resolveSameOriginUrl, stripUrlCredentials, trimLeadingSlash, trimSlashes, trimTrailingSlash, urlUserinfoRegex, withoutUrlCredentials };
141
239
 
142
240
  //# sourceMappingURL=url.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.js","names":[],"sources":["../../lib/util/url.ts"],"sourcesContent":["import {\n isArray,\n isNonEmptyString,\n isString,\n isUrlInstance,\n} from '@sindresorhus/is';\n// oxlint-disable-next-line no-restricted-imports\nimport _parseLinkHeader from 'parse-link-header';\nimport urlJoin from 'url-join';\nimport { logger } from '../logger/index.ts';\nimport { regEx } from './regex.ts';\n\nexport function joinUrlParts(...parts: string[]): string {\n return urlJoin(...parts);\n}\n\nexport function ensurePathPrefix(url: string, prefix: string): string {\n const parsed = new URL(url);\n const fullPath = parsed.pathname + parsed.search;\n if (fullPath.startsWith(prefix)) {\n return url;\n }\n return parsed.origin + prefix + fullPath;\n}\n\nexport function ensureTrailingSlash(url: string): string {\n return url.replace(regEx(/\\/?$/), '/');\n}\n\nexport function trimTrailingSlash(url: string): string {\n return url.replace(regEx(/\\/+$/), '');\n}\n\nexport function trimLeadingSlash(path: string): string {\n return path.replace(regEx(/^\\/+/), '');\n}\n\nexport function trimSlashes(path: string): string {\n return trimLeadingSlash(trimTrailingSlash(path));\n}\n\n/**\n * Resolves an input path against a base URL\n *\n * @param baseUrl - base URL to resolve against\n * @param input - input path (if this is a full URL, it will be returned)\n */\nexport function resolveBaseUrl(baseUrl: string, input: string | URL): string {\n const inputString = input.toString();\n\n let host;\n let pathname;\n try {\n ({ host, pathname } = new URL(inputString));\n } catch {\n pathname = inputString;\n }\n\n return host ? inputString : urlJoin(baseUrl, pathname || '');\n}\n\n/**\n * Replaces the path of a URL with a new path\n *\n * @param baseUrl - source URL\n * @param path - replacement path (if this is a full URL, it will be returned)\n */\nexport function replaceUrlPath(baseUrl: string | URL, path: string): string {\n if (parseUrl(path)) {\n return path;\n }\n\n const { origin } = isString(baseUrl) ? new URL(baseUrl) : baseUrl;\n return urlJoin(origin, path);\n}\n\n/**\n * Resolves a server-provided pagination \"next\" URL against the current request\n * URL, returning it only when it stays on the same origin.\n *\n * Registries paginate by returning a `Link` header (or Atom `<link rel=\"next\">`)\n * pointing at the next page.\n *\n * However, if we were to follow that URL without validating it, this could lead to us being redirected to a different host, which could lead to Server-Side Request Forgery (SSRF).\n *\n * This guard drops any `next` URL that resolves to a different origin.\n *\n * @param baseUrl - the URL of the request that produced `nextUrl`\n * @param nextUrl - the remote-server-provided pagination target (may be relative, and may be malicious)\n * @returns the resolved absolute URL if same-origin, otherwise `null`\n */\nexport function resolveSameOriginUrl(\n baseUrl: string | URL,\n nextUrl: string | URL,\n): string | null {\n const base = parseUrl(baseUrl);\n if (!base) {\n return null;\n }\n\n let resolved: URL;\n try {\n resolved = new URL(nextUrl.toString(), base);\n } catch {\n return null;\n }\n\n // If the base URL is HTTPS and the resolved URL is HTTP, but has no port specified, we can assume that the server intended to use HTTPS. This is a common misconfiguration in some registries.\n if (\n base.protocol === 'https:' &&\n resolved.protocol === 'http:' &&\n resolved.port === ''\n ) {\n logger.debug(`Detected protocol downgrade and fixed it: ${resolved.href}`);\n resolved.protocol = 'https:';\n }\n\n return resolved.origin === base.origin ? resolved.href : null;\n}\n\nexport function getQueryString(params: Record<string, any>): string {\n const usp = new URLSearchParams();\n for (const [k, v] of Object.entries(params)) {\n if (isArray<object>(v)) {\n for (const item of v) {\n // TODO: fix me?\n // oxlint-disable-next-line typescript/no-base-to-string\n usp.append(k, item.toString());\n }\n } else {\n usp.append(k, v.toString());\n }\n }\n return usp.toString();\n}\n\nexport function isHttpUrl(url: unknown): boolean {\n if (!isNonEmptyString(url) && !isUrlInstance(url)) {\n return false;\n }\n const protocol = parseUrl(url)?.protocol;\n return protocol === 'https:' || protocol === 'http:';\n}\n\nexport function parseUrl(url: URL | string | undefined | null): URL | null {\n if (!url) {\n return null;\n }\n\n if (url instanceof URL) {\n return url;\n }\n\n try {\n return new URL(url);\n } catch {\n return null;\n }\n}\n\n/**\n * Tries to create an URL object from either a full URL string or a hostname\n * @param url either the full url or a hostname\n * @returns an URL object or null\n */\nexport function createURLFromHostOrURL(url: string): URL | null {\n return parseUrl(url) ?? parseUrl(`https://${url}`);\n}\n\n/**\n * Removes the `user:password@` userinfo from a URL.\n *\n * Registries are sometimes configured with a URL that carries a placeholder such as `${USER}:${PASS}@`, and credentials embedded this way should not stop the URL from matching a plain `matchHost`.\n *\n * @returns the URL's `href` without userinfo, or `null` if `url` cannot be parsed\n */\nexport function stripUrlCredentials(url: URL): string;\nexport function stripUrlCredentials(url: string | URL): string | null;\nexport function stripUrlCredentials(url: string | URL): string | null {\n const parsed = parseUrl(url);\n if (!parsed) {\n return null;\n }\n if (!parsed.username && !parsed.password) {\n return parsed.href;\n }\n // clone rather than mutate: `parseUrl` returns the same instance it was given when `url` is already a `URL`\n const stripped = new URL(parsed.href);\n stripped.username = '';\n stripped.password = '';\n return stripped.href;\n}\n\nexport type LinkHeaderLinks = _parseLinkHeader.Links;\n\nexport function parseLinkHeader(\n linkHeader: string | null | undefined,\n): LinkHeaderLinks | null {\n if (!isNonEmptyString(linkHeader)) {\n return null;\n }\n if (linkHeader.length > 2000) {\n logger.warn({ linkHeader }, 'Link header too long.');\n return null;\n }\n return _parseLinkHeader(linkHeader);\n}\n\n/**\n * prefix https:// to hosts with port or path\n */\nexport function massageHostUrl(url: string): string {\n if (!url.includes('://') && url.includes('/')) {\n return `https://${url}`;\n }\n if (!url.includes('://') && url.includes(':')) {\n return `https://${url}`;\n }\n return url;\n}\n"],"mappings":";;;;;;AAYA,SAAgB,aAAa,GAAG,OAAyB;CACvD,OAAO,QAAQ,GAAG,KAAK;AACzB;AAEA,SAAgB,iBAAiB,KAAa,QAAwB;CACpE,MAAM,SAAS,IAAI,IAAI,GAAG;CAC1B,MAAM,WAAW,OAAO,WAAW,OAAO;CAC1C,IAAI,SAAS,WAAW,MAAM,GAC5B,OAAO;CAET,OAAO,OAAO,SAAS,SAAS;AAClC;AAEA,SAAgB,oBAAoB,KAAqB;CACvD,OAAO,IAAI,QAAQ,MAAM,MAAM,GAAG,GAAG;AACvC;AAEA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ts"],"sourcesContent":["import {\n isArray,\n isNonEmptyString,\n isObject,\n isString,\n isUrlInstance,\n} from '@sindresorhus/is';\n// oxlint-disable-next-line no-restricted-imports\nimport _parseLinkHeader from 'parse-link-header';\nimport urlJoin from 'url-join';\nimport { logger } from '../logger/index.ts';\nimport { regEx } from './regex.ts';\n\nexport function joinUrlParts(...parts: string[]): string {\n return urlJoin(...parts);\n}\n\nexport function ensurePathPrefix(url: string, prefix: string): string {\n const parsed = new URL(url);\n const fullPath = parsed.pathname + parsed.search;\n if (fullPath.startsWith(prefix)) {\n return url;\n }\n return parsed.origin + prefix + fullPath;\n}\n\nexport function ensureTrailingSlash(url: string): string {\n return url.replace(regEx(/\\/?$/), '/');\n}\n\nexport function trimTrailingSlash(url: string): string {\n return url.replace(regEx(/\\/+$/), '');\n}\n\nexport function trimLeadingSlash(path: string): string {\n return path.replace(regEx(/^\\/+/), '');\n}\n\nexport function trimSlashes(path: string): string {\n return trimLeadingSlash(trimTrailingSlash(path));\n}\n\n/**\n * Resolves an input path against a base URL\n *\n * @param baseUrl - base URL to resolve against\n * @param input - input path (if this is a full URL, it will be returned)\n */\nexport function resolveBaseUrl(baseUrl: string, input: string | URL): string {\n const inputString = input.toString();\n\n let host;\n let pathname;\n try {\n ({ host, pathname } = new URL(inputString));\n } catch {\n pathname = inputString;\n }\n\n return host ? inputString : urlJoin(baseUrl, pathname || '');\n}\n\n/**\n * Replaces the path of a URL with a new path\n *\n * @param baseUrl - source URL\n * @param path - replacement path (if this is a full URL, it will be returned)\n */\nexport function replaceUrlPath(baseUrl: string | URL, path: string): string {\n if (parseUrl(path)) {\n return path;\n }\n\n const { origin } = isString(baseUrl) ? new URL(baseUrl) : baseUrl;\n return urlJoin(origin, path);\n}\n\n/**\n * Resolves a server-provided pagination \"next\" URL against the current request\n * URL, returning it only when it stays on the same origin.\n *\n * Registries paginate by returning a `Link` header (or Atom `<link rel=\"next\">`)\n * pointing at the next page.\n *\n * However, if we were to follow that URL without validating it, this could lead to us being redirected to a different host, which could lead to Server-Side Request Forgery (SSRF).\n *\n * This guard drops any `next` URL that resolves to a different origin.\n *\n * @param baseUrl - the URL of the request that produced `nextUrl`\n * @param nextUrl - the remote-server-provided pagination target (may be relative, and may be malicious)\n * @returns the resolved absolute URL if same-origin, otherwise `null`\n */\nexport function resolveSameOriginUrl(\n baseUrl: string | URL,\n nextUrl: string | URL,\n): string | null {\n const base = parseUrl(baseUrl);\n if (!base) {\n return null;\n }\n\n let resolved: URL;\n try {\n resolved = new URL(nextUrl.toString(), base);\n } catch {\n return null;\n }\n\n // If the base URL is HTTPS and the resolved URL is HTTP, but has no port specified, we can assume that the server intended to use HTTPS. This is a common misconfiguration in some registries.\n if (\n base.protocol === 'https:' &&\n resolved.protocol === 'http:' &&\n resolved.port === ''\n ) {\n logger.debug(`Detected protocol downgrade and fixed it: ${resolved.href}`);\n resolved.protocol = 'https:';\n }\n\n return resolved.origin === base.origin ? resolved.href : null;\n}\n\nexport function getQueryString(params: Record<string, any>): string {\n const usp = new URLSearchParams();\n for (const [k, v] of Object.entries(params)) {\n if (isArray<object>(v)) {\n for (const item of v) {\n // TODO: fix me?\n // oxlint-disable-next-line typescript/no-base-to-string\n usp.append(k, item.toString());\n }\n } else {\n usp.append(k, v.toString());\n }\n }\n return usp.toString();\n}\n\nexport function isHttpUrl(url: unknown): boolean {\n if (!isNonEmptyString(url) && !isUrlInstance(url)) {\n return false;\n }\n const protocol = parseUrl(url)?.protocol;\n return protocol === 'https:' || protocol === 'http:';\n}\n\nexport function parseUrl(url: URL | string | undefined | null): URL | null {\n if (!url) {\n return null;\n }\n\n if (url instanceof URL) {\n return url;\n }\n\n try {\n return new URL(url);\n } catch {\n return null;\n }\n}\n\n/**\n * Tries to create an URL object from either a full URL string or a hostname\n * @param url either the full url or a hostname\n * @returns an URL object or null\n */\nexport function createURLFromHostOrURL(url: string): URL | null {\n return parseUrl(url) ?? parseUrl(`https://${url}`);\n}\n\n/**\n * Removes the `user:password@` userinfo from a URL.\n *\n * Registries are sometimes configured with a URL that carries a placeholder such as `${USER}:${PASS}@`, and credentials embedded this way should not stop the URL from matching a plain `matchHost`.\n *\n * @returns the URL's `href` without userinfo, or `null` if `url` cannot be parsed\n */\nexport function stripUrlCredentials(url: URL): string;\nexport function stripUrlCredentials(url: string | URL): string | null;\nexport function stripUrlCredentials(url: string | URL): string | null {\n const parsed = parseUrl(url);\n if (!parsed) {\n return null;\n }\n if (!parsed.username && !parsed.password) {\n return parsed.href;\n }\n // clone rather than mutate: `parseUrl` returns the same instance it was given when `url` is already a `URL`\n const stripped = new URL(parsed.href);\n stripped.username = '';\n stripped.password = '';\n return stripped.href;\n}\n\n/**\n * Matches the `scheme` and the `userinfo` of every URL inside a text, the userinfo ending at the last `@` before the path as in the URL standard.\n *\n * The text may not be a single URL but may contain several, e.g. a `replaceString`, a `managerData` value or a cache key, so we cannot perform URL parsing as-is\n *\n * A single URL is handled by {@link stripUrlCredentials} instead.\n */\nexport const urlUserinfoRegex = regEx(\n /(?<scheme>[a-z][a-z\\d+.-]*):\\/\\/(?<userinfo>[^/?#\\s]+)@/gi,\n);\n\n/**\n * Matches exactly one `${NAME}`, `${env.NAME}`, `${NAME:?msg}`, `${NAME?msg}`, upper-case `$NAME`, `${{ expression }}` or `{{ NAME }}` reference.\n */\nconst userinfoPlaceholderRegex = regEx(\n /^(?:\\$\\{(?:env\\.)?[A-Za-z_]\\w*(?::?\\?[^{}]*)?\\}|\\$[A-Z_][A-Z\\d_]*|\\$\\{\\{\\s*[^{}\\s][^{}]*\\}\\}|\\{\\{\\s*[A-Za-z_]\\w*\\s*\\}\\})$/,\n);\n\n/**\n * Usernames without a password of their own, which stand for a credential resolved at request time.\n *\n * `oauth2accesstoken` is Google Artifact Registry's, whose token the pypi and docker datasources fetch per request.\n *\n * @see https://docs.renovatebot.com/docker/#google-container-registry-google-artifact-registry\n */\nconst placeholderUsernames = new Set(['oauth2accesstoken']);\n\n/**\n * Whether `username` is a placeholder username such as `oauth2accesstoken`.\n */\nexport function isPlaceholderUsername(username: string): boolean {\n return placeholderUsernames.has(username);\n}\n\n/**\n * Decodes a percent-encoded userinfo part, or returns it as is when it is not valid percent-encoding.\n */\nexport function decodeUserinfo(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n}\n\n/**\n * Whether a percent-encoded userinfo part, once decoded, is exactly one `${NAME}`, `${env.NAME}`, `${NAME:?msg}`, `${NAME?msg}`, upper-case `$NAME`, `${{ expression }}` or `{{ NAME }}` placeholder.\n */\nexport function isUserinfoPlaceholder(value: string): boolean {\n return userinfoPlaceholderRegex.test(decodeUserinfo(value));\n}\n\nconst firstPathSegmentRegex = regEx(/^[^/?#\\s]*\\/(?<segment>[^/?#\\s]*)/);\n\n/**\n * Whether `username` equals, ignoring case, the first path segment of `rest`, the text following the `@` of a URL's userinfo.\n */\nfunction isFirstPathSegment(username: string, rest: string): boolean {\n const match = firstPathSegmentRegex.exec(rest);\n if (!match) {\n return false;\n }\n const { segment } = match.groups!;\n return decodeUserinfo(segment).toLowerCase() === username.toLowerCase();\n}\n\n/**\n * The minimum length of a username without a password which counts as a credential.\n */\nconst minUsernameCredentialLength = 16;\n\n/**\n * Whether a `scheme://userinfo@` followed by `rest` holds a credential once its parts are decoded:\n * a non-empty password other than a template placeholder, or a username of at least {@link minUsernameCredentialLength} characters with an empty or no password, except for an ssh scheme, a template placeholder, a placeholder username or a username equal to the first path segment.\n * A `docker://image:tag@digest` reference holds none.\n */\nexport function isCredentialUserinfo(\n scheme: string,\n userinfo: string,\n rest: string,\n): boolean {\n const lowerScheme = scheme.toLowerCase();\n if (lowerScheme === 'docker') {\n return false;\n }\n const [rawUsername, ...rawPasswordParts] = userinfo.split(':');\n const rawPassword = rawPasswordParts.join(':');\n if (rawPassword) {\n // a username next to a placeholder password is not a token of its own\n return !isUserinfoPlaceholder(rawPassword);\n }\n const username = decodeUserinfo(rawUsername);\n return (\n username.length >= minUsernameCredentialLength &&\n !lowerScheme.endsWith('ssh') &&\n !isUserinfoPlaceholder(rawUsername) &&\n !isPlaceholderUsername(username) &&\n !isFirstPathSegment(username, rest)\n );\n}\n\n/**\n * Whether `text` contains a URL with a `user:password@` or `token@` userinfo.\n */\nexport function hasUrlCredentials(text: string): boolean {\n for (const match of text.matchAll(urlUserinfoRegex)) {\n const { scheme, userinfo } = match.groups!;\n const rest = text.slice(match.index + match[0].length);\n if (isCredentialUserinfo(scheme, userinfo, rest)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Whether any string inside `value`, searched through arrays and object values, contains a URL with credentials.\n */\nexport function containsUrlCredentials(value: unknown): boolean {\n if (isString(value)) {\n return hasUrlCredentials(value);\n }\n if (isObject(value)) {\n return Object.values(value).some(containsUrlCredentials);\n }\n return false;\n}\n\n/**\n * Removes the `user:password@` or `token@` userinfo of every URL inside `text` that carries a credential, leaving the rest of `text` unchanged.\n */\nexport function withoutUrlCredentials(text: string): string {\n return text.replace(urlUserinfoRegex, (match: string, ...args: unknown[]) => {\n // the offset, the input and the named groups are the last arguments of a `replace()` callback\n const offset = args.at(-3) as number;\n const { scheme, userinfo } = args.at(-1) as Record<string, string>;\n const rest = text.slice(offset + match.length);\n return isCredentialUserinfo(scheme, userinfo, rest)\n ? `${scheme}://`\n : match;\n });\n}\n\nexport type LinkHeaderLinks = _parseLinkHeader.Links;\n\nexport function parseLinkHeader(\n linkHeader: string | null | undefined,\n): LinkHeaderLinks | null {\n if (!isNonEmptyString(linkHeader)) {\n return null;\n }\n if (linkHeader.length > 2000) {\n logger.warn({ linkHeader }, 'Link header too long.');\n return null;\n }\n return _parseLinkHeader(linkHeader);\n}\n\n/**\n * prefix https:// to hosts with port or path\n */\nexport function massageHostUrl(url: string): string {\n if (!url.includes('://') && url.includes('/')) {\n return `https://${url}`;\n }\n if (!url.includes('://') && url.includes(':')) {\n return `https://${url}`;\n }\n return url;\n}\n"],"mappings":";;;;;;AAaA,SAAgB,aAAa,GAAG,OAAyB;CACvD,OAAO,QAAQ,GAAG,KAAK;A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,OAAO,kBAAkB,KAAK;CAEhC,IAAI,SAAS,KAAK,GAChB,OAAO,OAAO,OAAO,KAAK,CAAC,CAAC,KAAK,sBAAsB;CAEzD,OAAO;AACT;;;;AAKA,SAAgB,sBAAsB,MAAsB;CAC1D,OAAO,KAAK,QAAQ,mBAAmB,OAAe,GAAG,SAAoB;EAE3E,MAAM,SAAS,KAAK,GAAG,EAAE;EACzB,MAAM,EAAE,QAAQ,aAAa,KAAK,GAAG,EAAE;EAEvC,OAAO,qBAAqB,QAAQ,UADvB,KAAK,MAAM,SAAS,MAAM,MACU,CAAC,IAC9C,GAAG,OAAO,OACV;CACN,CAAC;AACH;AAIA,SAAgB,gBACd,YACwB;CACxB,IAAI,CAAC,iBAAiB,UAAU,GAC9B,OAAO;CAET,IAAI,WAAW,SAAS,KAAM;EAC5B,OAAO,KAAK,EAAE,WAAW,GAAG,uBAAuB;EACnD,OAAO;CACT;CACA,OAAO,iBAAiB,UAAU;AACpC;;;;AAKA,SAAgB,eAAe,KAAqB;CAClD,IAAI,CAAC,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,GAAG,GAC1C,OAAO,WAAW;CAEpB,IAAI,CAAC,IAAI,SAAS,KAAK,KAAK,IAAI,SAAS,GAAG,GAC1C,OAAO,WAAW;CAEpB,OAAO;AACT"}
@@ -1,5 +1,6 @@
1
1
  import "../../constants/error-messages.js";
2
2
  import { logger } from "../../logger/index.js";
3
+ import { withoutUrlCredentials } from "../../util/url.js";
3
4
  import { getCache } from "../../util/cache/repository/index.js";
4
5
  import { getCachedBehindBaseResult } from "../../util/git/behind-base-branch-cache.js";
5
6
  import { getCachedConflictResult } from "../../util/git/conflicts-cache.js";
@@ -8,7 +9,14 @@ import { scm } from "../../modules/platform/scm.js";
8
9
  import { platform } from "../../modules/platform/index.js";
9
10
  import { getCachedPristineResult } from "../../util/git/pristine.js";
10
11
  import { getPrCache } from "./update/pr/pr-cache.js";
12
+ import { isString } from "@sindresorhus/is";
11
13
  //#region lib/workers/repository/cache.ts
14
+ /**
15
+ * Returns a shallow copy of `obj` with `withoutUrlCredentials` applied to every string value.
16
+ */
17
+ function withoutCredentials(obj) {
18
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, isString(value) ? withoutUrlCredentials(value) : value]));
19
+ }
12
20
  function generateBranchUpgradeCache(upgrade) {
13
21
  const { datasource, depName, depType, displayPending, manager, packageName, fixedVersion, currentVersion, newVersion, currentValue, newValue, currentDigest, newDigest, packageFile, sourceUrl, remediationNotPossible, updateType, isVulnerabilityAlert } = upgrade;
14
22
  const result = {
@@ -31,7 +39,7 @@ function generateBranchUpgradeCache(upgrade) {
31
39
  isVulnerabilityAlert
32
40
  };
33
41
  if (packageName) result.packageName = packageName;
34
- return result;
42
+ return withoutCredentials(result);
35
43
  }
36
44
  async function generateBranchCache(branch) {
37
45
  const { baseBranch, branchName, prBlockedBy, prTitle, result } = branch;
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","names":[],"sources":["../../../lib/workers/repository/cache.ts"],"sourcesContent":["import { REPOSITORY_CHANGED } from '../../constants/error-messages.ts';\nimport { logger } from '../../logger/index.ts';\nimport { platform } from '../../modules/platform/index.ts';\nimport { scm } from '../../modules/platform/scm.ts';\nimport { getCache } from '../../util/cache/repository/index.ts';\nimport type {\n BranchCache,\n BranchUpgradeCache,\n} from '../../util/cache/repository/types.ts';\nimport { getCachedBehindBaseResult } from '../../util/git/behind-base-branch-cache.ts';\nimport { getCachedConflictResult } from '../../util/git/conflicts-cache.ts';\nimport { getCachedModifiedResult } from '../../util/git/modified-cache.ts';\nimport { getCachedPristineResult } from '../../util/git/pristine.ts';\nimport type { BranchConfig, BranchUpgradeConfig } from '../types.ts';\nimport { getPrCache } from './update/pr/pr-cache.ts';\n\nfunction generateBranchUpgradeCache(\n upgrade: BranchUpgradeConfig,\n): BranchUpgradeCache {\n const {\n datasource,\n depName,\n depType,\n displayPending,\n manager,\n packageName,\n fixedVersion,\n currentVersion,\n newVersion,\n currentValue,\n newValue,\n currentDigest,\n newDigest,\n packageFile,\n sourceUrl,\n remediationNotPossible,\n updateType,\n isVulnerabilityAlert,\n } = upgrade;\n const result: BranchUpgradeCache = {\n datasource,\n depName,\n depType,\n displayPending,\n manager,\n fixedVersion,\n currentVersion,\n currentValue,\n newValue,\n newVersion,\n currentDigest,\n newDigest,\n packageFile,\n sourceUrl,\n remediationNotPossible,\n updateType,\n isVulnerabilityAlert,\n };\n if (packageName) {\n result.packageName = packageName;\n }\n return result;\n}\n\nasync function generateBranchCache(\n branch: BranchConfig,\n): Promise<BranchCache | null> {\n const { baseBranch, branchName, prBlockedBy, prTitle, result } = branch;\n try {\n const branchSha = await scm.getBranchCommit(branchName);\n const baseBranchSha = await scm.getBranchCommit(baseBranch);\n const pristine = getCachedPristineResult(branchName);\n let prNo = null;\n let isModified: boolean | undefined;\n let isBehindBase: boolean | undefined;\n let isConflicted: boolean | undefined;\n let commitTimestamp: string | undefined;\n if (baseBranchSha && branchSha) {\n const branchPr = await platform.getBranchPr(branchName, baseBranch);\n if (branchPr) {\n prNo = branchPr.number;\n }\n isModified = getCachedModifiedResult(branchName, branchSha) ?? undefined;\n isBehindBase =\n getCachedBehindBaseResult(\n branchName,\n branchSha,\n baseBranch,\n baseBranchSha,\n ) ?? undefined;\n isConflicted =\n getCachedConflictResult(\n branchName,\n branchSha,\n baseBranch,\n baseBranchSha,\n ) ?? undefined;\n // Get commit timestamp for hourly limit tracking\n const commitDate = await scm.getBranchUpdateDate(branchName);\n if (commitDate) {\n commitTimestamp = commitDate.toISO()!;\n }\n } else if (baseBranchSha && !branchSha && branch.prNo) {\n // if branch was deleted/ PR exists and ignored\n prNo = branch.prNo;\n }\n\n const automerge = !!branch.automerge;\n const upgrades: BranchUpgradeCache[] = branch.upgrades\n ? branch.upgrades.map(generateBranchUpgradeCache)\n : [];\n const commitFingerprint = branch.commitFingerprint;\n const prCache = getPrCache(branchName);\n\n return {\n automerge,\n baseBranchSha,\n baseBranch,\n commitFingerprint,\n commitTimestamp,\n branchName,\n isBehindBase,\n isConflicted,\n isModified,\n prBlockedBy,\n pristine,\n prCache,\n prNo,\n prTitle,\n result,\n sha: branchSha,\n upgrades,\n };\n } catch (error) {\n const err = error.err ?? error; // external host error nests err\n const errCodes = [401, 404];\n // istanbul ignore if\n if (errCodes.includes(err.response?.statusCode)) {\n logger.warn({ err, branchName }, 'HTTP error generating branch cache');\n return null;\n }\n if (err.message === REPOSITORY_CHANGED) {\n throw err;\n }\n logger.error({ err, branchName }, 'Error generating branch cache');\n return null;\n }\n}\n\nexport async function setBranchCache(branches: BranchConfig[]): Promise<void> {\n const branchCaches: BranchCache[] = [];\n for (const branch of branches) {\n const branchCache = await generateBranchCache(branch);\n if (branchCache) {\n branchCaches.push(branchCache);\n }\n }\n getCache().branches = branchCaches;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAS,2BACP,SACoB;CACpB,MAAM,EACJ,YACA,SACA,SACA,gBACA,SACA,aACA,cACA,gBACA,YACA,cACA,UACA,eACA,WACA,aACA,WACA,wBACA,YACA,yBACE;CACJ,MAAM,SAA6B;EACjC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,IAAI,aACF,OAAO,cAAc;CAEvB,OAAO;AACT;AAEA,eAAe,oBACb,QAC6B;CAC7B,MAAM,EAAE,YAAY,YAAY,aAAa,SAAS,WAAW;CACjE,IAAI;EACF,MAAM,YAAY,MAAM,IAAI,gBAAgB,UAAU;EACtD,MAAM,gBAAgB,MAAM,IAAI,gBAAgB,UAAU;EAC1D,MAAM,WAAW,wBAAwB,UAAU;EACnD,IAAI,OAAO;EACX,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI,iBAAiB,WAAW;GAC9B,MAAM,WAAW,MAAM,SAAS,YAAY,YAAY,UAAU;GAClE,IAAI,UACF,OAAO,SAAS;GAElB,aAAa,wBAAwB,YAAY,SAAS,KAAK,KAAA;GAC/D,eACE,0BACE,YACA,WACA,YACA,aACF,KAAK,KAAA;GACP,eACE,wBACE,YACA,WACA,YACA,aACF,KAAK,KAAA;GAEP,MAAM,aAAa,MAAM,IAAI,oBAAoB,UAAU;GAC3D,IAAI,YACF,kBAAkB,WAAW,MAAM;EAEvC,OAAO,IAAI,iBAAiB,CAAC,aAAa,OAAO,MAE/C,OAAO,OAAO;EAGhB,MAAM,YAAY,CAAC,CAAC,OAAO;EAC3B,MAAM,WAAiC,OAAO,WAC1C,OAAO,SAAS,IAAI,0BAA0B,IAC9C,CAAC;EACL,MAAM,oBAAoB,OAAO;EACjC,MAAM,UAAU,WAAW,UAAU;EAErC,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,KAAK;GACL;EACF;CACF,SAAS,OAAO;EACd,MAAM,MAAM,MAAM,OAAO;;EAGzB,IAAI,CAFc,KAAK,GAEZ,CAAC,CAAC,SAAS,IAAI,UAAU,UAAU,GAAG;GAC/C,OAAO,KAAK;IAAE;IAAK;GAAW,GAAG,oCAAoC;GACrE,OAAO;EACT;EACA,IAAI,IAAI,YAAA,sBACN,MAAM;EAER,OAAO,MAAM;GAAE;GAAK;EAAW,GAAG,+BAA+B;EACjE,OAAO;CACT;AACF;AAEA,eAAsB,eAAe,UAAyC;CAC5E,MAAM,eAA8B,CAAC;CACrC,KAAK,MAAM,UAAU,UAAU;EAC7B,MAAM,cAAc,MAAM,oBAAoB,MAAM;EACpD,IAAI,aACF,aAAa,KAAK,WAAW;CAEjC;CACA,SAAS,CAAC,CAAC,WAAW;AACxB"}
1
+ {"version":3,"file":"cache.js","names":[],"sources":["../../../lib/workers/repository/cache.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport { REPOSITORY_CHANGED } from '../../constants/error-messages.ts';\nimport { logger } from '../../logger/index.ts';\nimport { platform } from '../../modules/platform/index.ts';\nimport { scm } from '../../modules/platform/scm.ts';\nimport { getCache } from '../../util/cache/repository/index.ts';\nimport type {\n BranchCache,\n BranchUpgradeCache,\n} from '../../util/cache/repository/types.ts';\nimport { getCachedBehindBaseResult } from '../../util/git/behind-base-branch-cache.ts';\nimport { getCachedConflictResult } from '../../util/git/conflicts-cache.ts';\nimport { getCachedModifiedResult } from '../../util/git/modified-cache.ts';\nimport { getCachedPristineResult } from '../../util/git/pristine.ts';\nimport { withoutUrlCredentials } from '../../util/url.ts';\nimport type { BranchConfig, BranchUpgradeConfig } from '../types.ts';\nimport { getPrCache } from './update/pr/pr-cache.ts';\n\n/**\n * Returns a shallow copy of `obj` with `withoutUrlCredentials` applied to every string value.\n */\nfunction withoutCredentials<T extends object>(obj: T): T {\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n key,\n isString(value) ? withoutUrlCredentials(value) : value,\n ]),\n ) as T;\n}\n\nfunction generateBranchUpgradeCache(\n upgrade: BranchUpgradeConfig,\n): BranchUpgradeCache {\n const {\n datasource,\n depName,\n depType,\n displayPending,\n manager,\n packageName,\n fixedVersion,\n currentVersion,\n newVersion,\n currentValue,\n newValue,\n currentDigest,\n newDigest,\n packageFile,\n sourceUrl,\n remediationNotPossible,\n updateType,\n isVulnerabilityAlert,\n } = upgrade;\n const result: BranchUpgradeCache = {\n datasource,\n depName,\n depType,\n displayPending,\n manager,\n fixedVersion,\n currentVersion,\n currentValue,\n newValue,\n newVersion,\n currentDigest,\n newDigest,\n packageFile,\n sourceUrl,\n remediationNotPossible,\n updateType,\n isVulnerabilityAlert,\n };\n if (packageName) {\n result.packageName = packageName;\n }\n return withoutCredentials(result);\n}\n\nasync function generateBranchCache(\n branch: BranchConfig,\n): Promise<BranchCache | null> {\n const { baseBranch, branchName, prBlockedBy, prTitle, result } = branch;\n try {\n const branchSha = await scm.getBranchCommit(branchName);\n const baseBranchSha = await scm.getBranchCommit(baseBranch);\n const pristine = getCachedPristineResult(branchName);\n let prNo = null;\n let isModified: boolean | undefined;\n let isBehindBase: boolean | undefined;\n let isConflicted: boolean | undefined;\n let commitTimestamp: string | undefined;\n if (baseBranchSha && branchSha) {\n const branchPr = await platform.getBranchPr(branchName, baseBranch);\n if (branchPr) {\n prNo = branchPr.number;\n }\n isModified = getCachedModifiedResult(branchName, branchSha) ?? undefined;\n isBehindBase =\n getCachedBehindBaseResult(\n branchName,\n branchSha,\n baseBranch,\n baseBranchSha,\n ) ?? undefined;\n isConflicted =\n getCachedConflictResult(\n branchName,\n branchSha,\n baseBranch,\n baseBranchSha,\n ) ?? undefined;\n // Get commit timestamp for hourly limit tracking\n const commitDate = await scm.getBranchUpdateDate(branchName);\n if (commitDate) {\n commitTimestamp = commitDate.toISO()!;\n }\n } else if (baseBranchSha && !branchSha && branch.prNo) {\n // if branch was deleted/ PR exists and ignored\n prNo = branch.prNo;\n }\n\n const automerge = !!branch.automerge;\n const upgrades: BranchUpgradeCache[] = branch.upgrades\n ? branch.upgrades.map(generateBranchUpgradeCache)\n : [];\n const commitFingerprint = branch.commitFingerprint;\n const prCache = getPrCache(branchName);\n\n return {\n automerge,\n baseBranchSha,\n baseBranch,\n commitFingerprint,\n commitTimestamp,\n branchName,\n isBehindBase,\n isConflicted,\n isModified,\n prBlockedBy,\n pristine,\n prCache,\n prNo,\n prTitle,\n result,\n sha: branchSha,\n upgrades,\n };\n } catch (error) {\n const err = error.err ?? error; // external host error nests err\n const errCodes = [401, 404];\n // istanbul ignore if\n if (errCodes.includes(err.response?.statusCode)) {\n logger.warn({ err, branchName }, 'HTTP error generating branch cache');\n return null;\n }\n if (err.message === REPOSITORY_CHANGED) {\n throw err;\n }\n logger.error({ err, branchName }, 'Error generating branch cache');\n return null;\n }\n}\n\nexport async function setBranchCache(branches: BranchConfig[]): Promise<void> {\n const branchCaches: BranchCache[] = [];\n for (const branch of branches) {\n const branchCache = await generateBranchCache(branch);\n if (branchCache) {\n branchCaches.push(branchCache);\n }\n }\n getCache().branches = branchCaches;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,SAAS,mBAAqC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,CAAC;EACL,MAAM,oBAAoB,OAAO;EACjC,MAAM,UAAU,WAAW,UAAU;EAErC,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,KAAK;GACL;EACF;CACF,SAAS,OAAO;EACd,MAAM,MAAM,MAAM,OAAO;;EAGzB,IAAI,CAFc,KAAK,GAEZ,CAAC,CAAC,SAAS,IAAI,UAAU,UAAU,GAAG;GAC/C,OAAO,KAAK;IAAE;IAAK;GAAW,GAAG,oCAAoC;GACrE,OAAO;EACT;EACA,IAAI,IAAI,YAAA,sBACN,MAAM;EAER,OAAO,MAAM;GAAE;GAAK;EAAW,GAAG,+BAA+B;EACjE,OAAO;CACT;AACF;AAEA,eAAsB,eAAe,UAAyC;CAC5E,MAAM,eAA8B,CAAC;CACrC,KAAK,MAAM,UAAU,UAAU;EAC7B,MAAM,cAAc,MAAM,oBAAoB,MAAM;EACpD,IAAI,aACF,aAAa,KAAK,WAAW;CAEjC;CACA,SAAS,CAAC,CAAC,WAAW;AACxB"}
@@ -204,7 +204,7 @@ function headersByIdentity(rules) {
204
204
  */
205
205
  function isWithinHost(matchHost, adminMatchHost) {
206
206
  const url = parseUrl(matchHost) ? matchHost : `https://${matchHost}`;
207
- return matchesHost(url, adminMatchHost);
207
+ return matchesHost(url, adminMatchHost, { prefixOnly: true });
208
208
  }
209
209
  /**
210
210
  * Migrate a config, tolerating a migration which throws.