-
Notifications
You must be signed in to change notification settings - Fork 4
Harden changelog workflows against concurrency DoS, TOCTOU, and injection #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,7 @@ | ||||||
| const TITLE = '### 📋 Changelog'; | ||||||
|
|
||||||
| const escapeMarkdown = (s) => s.replace(/([[\]()\\`*_{}#+\-.!|])/g, '\\$1'); | ||||||
|
||||||
| const escapeMarkdown = (s) => s.replace(/([[\]()\\`*_{}#+\-.!|])/g, '\\$1'); | |
| const escapeMarkdown = (s) => s.replace(/([[\]()\\])/g, '\\$1'); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,17 +1,19 @@ | ||||||
| const { TITLE, upsertComment } = require('./comment-helper'); | ||||||
| const { TITLE, upsertComment, escapeMarkdown } = require('./comment-helper'); | ||||||
|
|
||||||
| module.exports = async ({ github, context, core }) => { | ||||||
| const prNumber = parseInt(process.env.PR_NUMBER, 10); | ||||||
| const branch = process.env.HEAD_REF; | ||||||
| const changelogFile = process.env.CHANGELOG_FILE; | ||||||
| const { owner, repo } = context.repo; | ||||||
| const viewUrl = `https://github.com/${owner}/${repo}/blob/${branch}/${changelogFile}`; | ||||||
| const editUrl = `https://github.com/${owner}/${repo}/edit/${branch}/${changelogFile}`; | ||||||
| const safeBranch = encodeURIComponent(branch); | ||||||
|
||||||
| const safeBranch = encodeURIComponent(branch); | |
| const safeBranch = branch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking out the PR by SHA will typically leave the repo in a detached HEAD state. The later
Commit changelogstep runsgit pushwithout specifying a ref, which usually fails from detached HEAD (and can also push to an unintended ref if push.default is configured). To keep the TOCTOU fix while still pushing to the PR branch, create/check out a local branch athead-refafter verifying the SHA (or configure checkout to land on the branch) before committing/pushing.