-
-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathcheck-auth-token-changes.js
More file actions
47 lines (40 loc) · 1.43 KB
/
Copy pathcheck-auth-token-changes.js
File metadata and controls
47 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const AUTH_TOKEN_PATTERN = /\b(SENTRY_AUTH_TOKEN|auth[._]token)\b|[Aa]uth[Tt]oken/;
const EXCLUDED_PATHS = [
/^\.github\//,
/^CHANGELOG\.md$/,
];
module.exports = async function ({ fail, warn, __, ___, danger }) {
const allChangedFiles = [
...danger.git.modified_files,
...danger.git.created_files,
].filter(file => !EXCLUDED_PATHS.some(pattern => pattern.test(file)));
const flaggedFiles = [];
for (const file of allChangedFiles) {
try {
const diff = await danger.git.structuredDiffForFile(file);
if (!diff) {
continue;
}
const hasAuthTokenChange = diff.chunks.some(chunk =>
chunk.changes.some(change =>
change.add && AUTH_TOKEN_PATTERN.test(change.content)
)
);
if (hasAuthTokenChange) {
flaggedFiles.push(file);
}
} catch (_error) {
// Skip files where diff fails (e.g. binary files)
}
}
if (flaggedFiles.length > 0) {
const fileList = flaggedFiles.map(file => `- \`${file}\``).join("\n");
warn(
`### ⚠️ Auth token handling changes detected\n\n` +
`This PR modifies code related to Sentry auth token handling. ` +
`Please ensure no auth tokens are accidentally exposed or mishandled. ` +
`See [GHSA-68c2-4mpx-qh95](https://github.com/getsentry/sentry-react-native/security/advisories/GHSA-68c2-4mpx-qh95) for context.\n\n` +
`Files with auth token changes:\n${fileList}`
);
}
};