(path: string)
| 46 | } |
| 47 | |
| 48 | export function isSensitiveFile(path: string): boolean { |
| 49 | const name = basename(path); |
| 50 | const comparableName = comparable(name); |
| 51 | const comparablePath = comparable(path); |
| 52 | |
| 53 | if (ENV_EXEMPTIONS.has(comparableName)) return false; |
| 54 | if (PUBLIC_KEY_BASENAMES.has(comparableName)) return false; |
| 55 | if (SENSITIVE_BASENAMES.has(comparableName)) return true; |
| 56 | if (comparableName.startsWith(ENV_PREFIX)) return true; |
| 57 | |
| 58 | for (const prefix of SENSITIVE_BASENAME_PREFIXES) { |
| 59 | if (comparableName === prefix) return true; |
| 60 | // Catch rename-shielded variants without flagging unrelated filenames |
| 61 | // like `id_rsafoo` or ordinary JSON files like `credentials.json`. |
| 62 | if (comparableName.length > prefix.length && comparableName.startsWith(prefix)) { |
| 63 | const suffix = comparableName.slice(prefix.length); |
| 64 | const next = suffix[0]; |
| 65 | if (next === '-' || next === '_') return true; |
| 66 | if (next === '.' && SENSITIVE_DOT_VARIANT_SUFFIX_SET.has(suffix)) return true; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | for (const suffixParts of SENSITIVE_PATH_SUFFIXES) { |
| 71 | const suffix = suffixParts.join('/'); |
| 72 | const comparableSuffix = comparable(suffix); |
| 73 | if ( |
| 74 | comparablePath.endsWith(`/${comparableSuffix}`) || |
| 75 | comparablePath.includes(`/${comparableSuffix}/`) |
| 76 | ) { |
| 77 | return true; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return false; |
| 82 | } |
no test coverage detected