@@ -11,14 +11,13 @@ jobs:
1111 runs-on : ubuntu-latest
1212 if : github.repository == 'sveltejs/svelte' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
1313 permissions :
14- issues : write # to add / delete reactions
14+ issues : write # to add / delete reactions, post comments
1515 pull-requests : write # to read PR data, and to add labels
1616 actions : read # to check workflow status
1717 contents : read # to clone the repo
1818 steps :
19- - name : monitor action permissions
20- - name : check user authorization # user needs triage permission
21- uses : actions/github-script@v7
19+ - name : Check User Permissions
20+ uses : actions/github-script@v8
2221 id : check-permissions
2322 with :
2423 script : |
5756 }
5857
5958 - name : Get PR Data
60- uses : actions/github-script@v7
59+ uses : actions/github-script@v8
6160 id : get-pr-data
6261 with :
6362 script : |
6766 repo: context.repo.repo,
6867 pull_number: context.issue.number
6968 })
69+
70+ const commentCreatedAt = new Date(context.payload.comment.created_at)
71+ const commitPushedAt = new Date(pr.head.repo.pushed_at)
72+
73+ console.log(`Comment created at: ${commentCreatedAt.toISOString()}`)
74+ console.log(`PR last pushed at: ${commitPushedAt.toISOString()}`)
75+
76+ // Check if any commits were pushed after the comment was created
77+ if (commitPushedAt > commentCreatedAt) {
78+ const errorMsg = [
79+ '⚠️ Security warning: PR was updated after the trigger command was posted.',
80+ '',
81+ `Comment posted at: ${commentCreatedAt.toISOString()}`,
82+ `PR last pushed at: ${commitPushedAt.toISOString()}`,
83+ '',
84+ 'This could indicate an attempt to inject code after approval.',
85+ 'Please review the latest changes and re-run /ecosystem-ci run if they are acceptable.'
86+ ].join('\n')
87+
88+ core.setFailed(errorMsg)
89+
90+ await github.rest.issues.createComment({
91+ owner: context.repo.owner,
92+ repo: context.repo.repo,
93+ issue_number: context.issue.number,
94+ body: errorMsg
95+ })
96+
97+ throw new Error('PR was pushed to after comment was created')
98+ }
99+
70100 return {
71101 num: context.issue.number,
72102 branchName: pr.head.ref,
@@ -85,15 +115,16 @@ jobs:
85115 svelte-ecosystem-ci
86116
87117 - name : Trigger Downstream Workflow
88- uses : actions/github-script@v7
118+ uses : actions/github-script@v8
89119 id : trigger
90120 env :
91121 COMMENT : ${{ github.event.comment.body }}
122+ PR_DATA : ${{ steps.get-pr-data.outputs.result }}
92123 with :
93124 github-token : ${{ steps.generate-token.outputs.token }}
94125 script : |
95126 const comment = process.env.COMMENT.trim()
96- const prData = ${{ steps.get-pr-data.outputs.result }}
127+ const prData = JSON.parse(process.env.PR_DATA)
97128
98129 const suite = comment.split('\n')[0].replace(/^\/ecosystem-ci run/, '').trim()
99130
0 commit comments