|
| 1 | +// Copyright 2021 The Witness Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package environment |
| 16 | + |
| 17 | +// sourced from https://github.com/Puliczek/awesome-list-of-secrets-in-environment-variables/blob/main/raw_list.txt |
| 18 | +func DefaultBlockList() map[string]struct{} { |
| 19 | + return map[string]struct{}{ |
| 20 | + "AWS_ACCESS_KEY_ID": {}, |
| 21 | + "AWS_SECRET_ACCESS_KEY": {}, |
| 22 | + "AMAZON_AWS_ACCESS_KEY_ID": {}, |
| 23 | + "AMAZON_AWS_SECRET_ACCESS_KEY": {}, |
| 24 | + "ALGOLIA_API_KEY": {}, |
| 25 | + "AZURE_CLIENT_ID": {}, |
| 26 | + "AZURE_CLIENT_SECRET": {}, |
| 27 | + "AZURE_USERNAME": {}, |
| 28 | + "AZURE_PASSWORD": {}, |
| 29 | + "MSI_ENDPOINT": {}, |
| 30 | + "MSI_SECRET": {}, |
| 31 | + "binance_api": {}, |
| 32 | + "binance_secret": {}, |
| 33 | + "BITTREX_API_KEY": {}, |
| 34 | + "BITTREX_API_SECRET": {}, |
| 35 | + "CF_PASSWORD": {}, |
| 36 | + "CF_USERNAME": {}, |
| 37 | + "CODECLIMATE_REPO_TOKEN": {}, |
| 38 | + "COVERALLS_REPO_TOKEN": {}, |
| 39 | + "CIRCLE_TOKEN": {}, |
| 40 | + "DIGITALOCEAN_ACCESS_TOKEN": {}, |
| 41 | + "DOCKER_EMAIL": {}, |
| 42 | + "DOCKER_PASSWORD": {}, |
| 43 | + "DOCKER_USERNAME": {}, |
| 44 | + "DOCKERHUB_PASSWORD": {}, |
| 45 | + "FACEBOOK_APP_ID": {}, |
| 46 | + "FACEBOOK_APP_SECRET": {}, |
| 47 | + "FACEBOOK_ACCESS_TOKEN": {}, |
| 48 | + "FIREBASE_TOKEN": {}, |
| 49 | + "FOSSA_API_KEY": {}, |
| 50 | + "GH_TOKEN": {}, |
| 51 | + "GH_ENTERPRISE_TOKEN": {}, |
| 52 | + "GOOGLE_APPLICATION_CREDENTIALS": {}, |
| 53 | + "GOOGLE_API_KEY": {}, |
| 54 | + "CI_DEPLOY_USER": {}, |
| 55 | + "CI_DEPLOY_PASSWORD": {}, |
| 56 | + "GITLAB_USER_LOGIN": {}, |
| 57 | + "CI_JOB_JWT": {}, |
| 58 | + "CI_JOB_JWT_V2": {}, |
| 59 | + "CI_JOB_TOKEN": {}, |
| 60 | + "HEROKU_API_KEY": {}, |
| 61 | + "HEROKU_API_USER": {}, |
| 62 | + "MAILGUN_API_KEY": {}, |
| 63 | + "MCLI_PRIVATE_API_KEY": {}, |
| 64 | + "MCLI_PUBLIC_API_KEY": {}, |
| 65 | + "NGROK_TOKEN": {}, |
| 66 | + "NGROK_AUTH_TOKEN": {}, |
| 67 | + "NPM_AUTH_TOKEN": {}, |
| 68 | + "OKTA_CLIENT_ORGURL": {}, |
| 69 | + "OKTA_CLIENT_TOKEN": {}, |
| 70 | + "OKTA_OAUTH2_CLIENTSECRET": {}, |
| 71 | + "OKTA_OAUTH2_CLIENTID": {}, |
| 72 | + "OKTA_AUTHN_GROUPID": {}, |
| 73 | + "OS_USERNAME": {}, |
| 74 | + "OS_PASSWORD": {}, |
| 75 | + "PERCY_TOKEN": {}, |
| 76 | + "SAUCE_ACCESS_KEY": {}, |
| 77 | + "SAUCE_USERNAME": {}, |
| 78 | + "SENTRY_AUTH_TOKEN": {}, |
| 79 | + "SLACK_TOKEN": {}, |
| 80 | + "SNYK_TOKEN": {}, |
| 81 | + "square_access_token": {}, |
| 82 | + "square_oauth_secret": {}, |
| 83 | + "STRIPE_API_KEY": {}, |
| 84 | + "STRIPE_DEVICE_NAME": {}, |
| 85 | + "SURGE_TOKEN": {}, |
| 86 | + "SURGE_LOGIN": {}, |
| 87 | + "TWILIO_ACCOUNT_SID": {}, |
| 88 | + "CONSUMER_KEY": {}, |
| 89 | + "CONSUMER_SECRET": {}, |
| 90 | + "TRAVIS_SUDO": {}, |
| 91 | + "TRAVIS_OS_NAME": {}, |
| 92 | + "TRAVIS_SECURE_ENV_VARS": {}, |
| 93 | + "VAULT_TOKEN": {}, |
| 94 | + "VAULT_CLIENT_KEY": {}, |
| 95 | + "TOKEN": {}, |
| 96 | + "VULTR_ACCESS": {}, |
| 97 | + "VULTR_SECRET": {}, |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +// FilterEnvironmentArray expects an array of strings representing environment variables. Each element of the array is expected to be in the format of "KEY=VALUE". |
| 102 | +// blockList is the list of elements to filter from variables, and for each element of variables that does not appear in the blockList onAllowed will be called. |
| 103 | +func FilterEnvironmentArray(variables []string, blockList map[string]struct{}, onAllowed func(key, val, orig string)) { |
| 104 | + for _, v := range variables { |
| 105 | + key, val := splitVariable(v) |
| 106 | + if _, inBlockList := blockList[key]; inBlockList { |
| 107 | + continue |
| 108 | + } |
| 109 | + |
| 110 | + onAllowed(key, val, v) |
| 111 | + } |
| 112 | +} |
0 commit comments