Skip to content

Commit

Permalink
meta: security hardening for github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev authored May 10, 2024
1 parent a923fed commit 9e5aef9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/verify-safe-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Validate Pull Request

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
validate:
runs-on: ubuntu-latest

Check failure on line 10 in .github/workflows/verify-safe-pr.yml

View workflow job for this annotation

GitHub Actions / lint-yaml

10:1 [trailing-spaces] trailing spaces
steps:
- name: Check PR values for unsafe characters

Check failure on line 12 in .github/workflows/verify-safe-pr.yml

View workflow job for this annotation

GitHub Actions / lint-yaml

12:5 [indentation] wrong indentation: expected 6 but found 4
id: check_values
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const valuesToCheck = [
context.payload.pull_request.user.email,
context.payload.pull_request.head.ref,
context.payload.pull_request.base.ref,
context.payload.pull_request.base.user.login,
context.payload.pull_request.head.repo.full_name
];
const regex = /[<>'"&;{}]/;
const unsafeValues = valuesToCheck.filter(value => regex.test(value));
if (unsafeValues.length > 0) {
core.setOutput('unsafeValues', unsafeValues.join(', '));
core.setFailed('One of the PR values contains potentially unsafe characters');
} else {
console.log('All values are safe.');
}
- name: Leave comment on PR
if: steps.check_values.outputs.unsafeValues != ''
run: |
const unsafeValues = process.env.UNSAFE_VALUES.split(', ');
const commentBody = `Potential security issue: The following values contain potentially unsafe characters: ${unsafeValues.join(', ')}`;

Check failure on line 39 in .github/workflows/verify-safe-pr.yml

View workflow job for this annotation

GitHub Actions / lint-yaml

39:1 [trailing-spaces] trailing spaces
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});

0 comments on commit 9e5aef9

Please sign in to comment.