|
3 | 3 | * |
4 | 4 | * Credentials come from the GRADLE_CACHE_URL / GRADLE_CACHE_USERNAME / |
5 | 5 | * GRADLE_CACHE_PASSWORD environment variables (CI secrets), or a |
6 | | - * local.properties / config.properties entry for local use. Push is enabled |
7 | | - * only when credentials are present, so fork PRs (which have no secrets) are |
8 | | - * pull-only and cannot poison the cache. |
| 6 | + * local.properties / config.properties entry for local use. Writes to the |
| 7 | + * cache happen only from trusted events (local dev, push, merge_group) with |
| 8 | + * credentials present, so pull-request runs (and credential-less fork PRs) |
| 9 | + * stay pull-only and cannot poison the cache. |
9 | 10 | */ |
10 | 11 |
|
11 | 12 | def getMeshProperty(String key) { |
@@ -37,17 +38,22 @@ buildCache { |
37 | 38 | def cacheUsername = getMeshProperty("GRADLE_CACHE_USERNAME")?.trim() |
38 | 39 | def cachePassword = getMeshProperty("GRADLE_CACHE_PASSWORD")?.trim() |
39 | 40 | if (cacheUrl) { |
| 41 | + // HTTPS + valid TLS enforced (no allowInsecureProtocol / no |
| 42 | + // allowUntrustedServer): the cache server must present a trusted |
| 43 | + // certificate over TLS. |
40 | 44 | url = cacheUrl.endsWith("/") ? cacheUrl : "${cacheUrl}/" |
41 | 45 | if (cacheUsername && cachePassword) { |
42 | 46 | credentials { |
43 | 47 | username = cacheUsername |
44 | 48 | password = cachePassword |
45 | 49 | } |
46 | 50 | } |
47 | | - allowInsecureProtocol = true |
48 | | - allowUntrustedServer = true |
49 | | - // Push only when credentials exist -> fork PRs are pull-only. |
50 | | - push = (cacheUsername && cachePassword) |
| 51 | + // Write only from trusted events (local dev, push to a protected |
| 52 | + // branch, or the merge queue) with credentials — never from |
| 53 | + // pull_request runs, so unmerged code can't poison the cache. |
| 54 | + def eventName = System.getenv("GITHUB_EVENT_NAME") |
| 55 | + def trustedForPush = eventName == null || eventName == "push" || eventName == "merge_group" |
| 56 | + push = (cacheUsername && cachePassword && trustedForPush) |
51 | 57 | enabled = true |
52 | 58 | } else { |
53 | 59 | enabled = false |
|
0 commit comments