|
| 1 | +/** |
| 2 | + * @name Storage of sensitive information in GitHub Actions artifact |
| 3 | + * @description Including sensitive information in a GitHub Actions artifact can |
| 4 | + * expose it to an attacker. |
| 5 | + * @kind problem |
| 6 | + * @problem.severity error |
| 7 | + * @security-severity 7.5 |
| 8 | + * @precision high |
| 9 | + * @id js/actions/actions-artifact-leak |
| 10 | + * @tags security |
| 11 | + * external/cwe/cwe-312 |
| 12 | + * external/cwe/cwe-315 |
| 13 | + * external/cwe/cwe-359 |
| 14 | + */ |
| 15 | + |
| 16 | +import javascript |
| 17 | +import semmle.javascript.Actions |
| 18 | + |
| 19 | +/** |
| 20 | + * A step that uses `actions/checkout` action. |
| 21 | + */ |
| 22 | +class ActionsCheckoutStep extends Actions::Step { |
| 23 | + ActionsCheckoutStep() { this.getUses().getGitHubRepository() = "actions/checkout" } |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * A `with:`/`persist-credentials` field sibling to `uses: actions/checkout`. |
| 28 | + */ |
| 29 | +class ActionsCheckoutWithPersistCredentials extends YamlNode, YamlScalar { |
| 30 | + ActionsCheckoutStep step; |
| 31 | + |
| 32 | + ActionsCheckoutWithPersistCredentials() { |
| 33 | + step.lookup("with").(YamlMapping).lookup("persist-credentials") = this |
| 34 | + } |
| 35 | + |
| 36 | + /** Gets the step this field belongs to. */ |
| 37 | + ActionsCheckoutStep getStep() { result = step } |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * A `with:`/`path` field sibling to `uses: actions/checkout`. |
| 42 | + */ |
| 43 | +class ActionsCheckoutWithPath extends YamlNode, YamlString { |
| 44 | + ActionsCheckoutStep step; |
| 45 | + |
| 46 | + ActionsCheckoutWithPath() { step.lookup("with").(YamlMapping).lookup("path") = this } |
| 47 | + |
| 48 | + /** Gets the step this field belongs to. */ |
| 49 | + ActionsCheckoutStep getStep() { result = step } |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * A step that uses `actions/upload-artifact` action. |
| 54 | + */ |
| 55 | +class ActionsUploadArtifactStep extends Actions::Step { |
| 56 | + ActionsUploadArtifactStep() { this.getUses().getGitHubRepository() = "actions/upload-artifact" } |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * A `with:`/`path` field sibling to `uses: actions/upload-artifact`. |
| 61 | + */ |
| 62 | +class ActionsUploadArtifactWithPath extends YamlNode, YamlString { |
| 63 | + ActionsUploadArtifactStep step; |
| 64 | + |
| 65 | + ActionsUploadArtifactWithPath() { step.lookup("with").(YamlMapping).lookup("path") = this } |
| 66 | + |
| 67 | + /** Gets the step this field belongs to. */ |
| 68 | + ActionsUploadArtifactStep getStep() { result = step } |
| 69 | +} |
| 70 | + |
| 71 | +from ActionsCheckoutStep checkout, ActionsUploadArtifactStep upload, Actions::Job job, int i, int j |
| 72 | +where |
| 73 | + checkout.getJob() = job and |
| 74 | + upload.getJob() = job and |
| 75 | + job.getStep(i) = checkout and |
| 76 | + job.getStep(j) = upload and |
| 77 | + j = i + 1 and |
| 78 | + upload.getUses().getVersion() = |
| 79 | + [ |
| 80 | + "v4.3.6", "834a144ee995460fba8ed112a2fc961b36a5ec5a", // |
| 81 | + "v4.3.5", "89ef406dd8d7e03cfd12d9e0a4a378f454709029", // |
| 82 | + "v4.3.4", "0b2256b8c012f0828dc542b3febcab082c67f72b", // |
| 83 | + "v4.3.3", "65462800fd760344b1a7b4382951275a0abb4808", // |
| 84 | + "v4.3.2", "1746f4ab65b179e0ea60a494b83293b640dd5bba", // |
| 85 | + "v4.3.1", "5d5d22a31266ced268874388b861e4b58bb5c2f3", // |
| 86 | + "v4.3.0", "26f96dfa697d77e81fd5907df203aa23a56210a8", // |
| 87 | + "v4.2.0", "694cdabd8bdb0f10b2cea11669e1bf5453eed0a6", // |
| 88 | + "v4.1.0", "1eb3cb2b3e0f29609092a73eb033bb759a334595", // |
| 89 | + "v4.0.0", "c7d193f32edcb7bfad88892161225aeda64e9392", // |
| 90 | + ] and |
| 91 | + ( |
| 92 | + not exists(ActionsCheckoutWithPersistCredentials persist | persist.getStep() = checkout) |
| 93 | + or |
| 94 | + exists(ActionsCheckoutWithPersistCredentials persist | |
| 95 | + persist.getStep() = checkout and |
| 96 | + persist.getValue() = "true" |
| 97 | + ) |
| 98 | + ) and |
| 99 | + ( |
| 100 | + not exists(ActionsCheckoutWithPath path | path.getStep() = checkout) and |
| 101 | + exists(ActionsUploadArtifactWithPath path | |
| 102 | + path.getStep() = upload and path.getValue() = [".", "*"] |
| 103 | + ) |
| 104 | + or |
| 105 | + exists(ActionsCheckoutWithPath checkout_path, ActionsUploadArtifactWithPath upload_path | |
| 106 | + checkout_path.getValue() + ["", "/*"] = upload_path.getValue() and |
| 107 | + checkout_path.getStep() = checkout and |
| 108 | + upload_path.getStep() = upload |
| 109 | + ) |
| 110 | + ) |
| 111 | +select upload, "A secret may be exposed in an artifact." |
0 commit comments