Skip to content

Commit 0b27d4a

Browse files
committed
feat: mitigating script injection attacks by passing issue body as env var (#42)
BREAKING CHANGE: Add `issue-body` argument which is required from v3 onwards To mitigate script injection attacks, github-issue-parser v3 will require workflow authors to pass the issue body as an argument. By doing so you will follow GitHub's [Good practices for mitigating script injection attacks ](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#good-practices-for-mitigating-script-injection-attacks) ```yml - uses: stefanbuck/github-issue-parser@v3 id: issue-parser with: issue-body: ${{ github.event.issue.body }} # required template-path: .github/ISSUE_TEMPLATE/bug-report.yml # optional but recommended ```
1 parent 1d341cb commit 0b27d4a

File tree

16 files changed

+3731
-167
lines changed

16 files changed

+3731
-167
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
git config user.email [email protected]
2121
git add .gitignore dist/
2222
git commit -m "build"
23-
git push --force https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/v2
23+
git push --force https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/v3
2424
env:
2525
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2626
- run: npx semantic-release

README.md

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,104 +7,86 @@ Use this action to convert issues into a unified JSON structure. Read the [Codel
77
## Setup
88

99
```yml
10-
- uses: stefanbuck/github-issue-parser@v2
10+
- uses: stefanbuck/github-issue-parser@v3
1111
id: issue-parser
1212
with:
13-
template-path: .github/ISSUE_TEMPLATE/bug-report.yml
13+
issue-body: ${{ github.event.issue.body }} # required
14+
template-path: .github/ISSUE_TEMPLATE/bug-report.yml # optional but recommended
1415

15-
- run: echo '${{ steps.issue-parser.outputs.jsonString }}' > bug-details.json
16+
- run: cat ${HOME}/issue-parser-result.json
1617

17-
- run: echo '${{ steps.issue-parser.outputs.issueparser_your_contact_details }}'
18+
- run: echo $FAVORITE_DISH
19+
env:
20+
FAVORITE_DISH: ${{ steps.issue-parser.outputs.issueparser_favorite_dish }}
1821
```
1922
20-
`template-path` is optional and meant to be used with Issue Forms.
21-
2223
## Example
2324
2425
Given an issue form
2526
2627
```yml
27-
name: Bug
28-
description: Something is broken
29-
30-
title: "Order Pizza"
31-
3228
body:
3329
- type: input
34-
id: contact
35-
attributes:
36-
label: Your contact details
37-
validations:
38-
required: true
39-
40-
- type: input
41-
id: what_happened
42-
attributes:
43-
label: What happened?
44-
validations:
45-
required: true
46-
47-
- type: input
48-
id: version
49-
attributes:
50-
label: Version
51-
validations:
52-
required: true
53-
54-
- type: input
55-
id: browsers
30+
id: favorite_dish
5631
attributes:
57-
label: What browsers are you seeing the problem on?
32+
label: What's your favorite dish?
5833
validations:
5934
required: true
6035

6136
- type: checkboxes
62-
id: what_else
37+
id: favorite_color
6338
attributes:
64-
label: What else?
39+
label: What's your preferred color?
6540
options:
66-
- label: Never give up
67-
- label: Hot Dog is a Sandwich
41+
- label: Red
42+
- label: Green
43+
- label: Blue
6844
```
6945
7046
And an issue body
7147
7248
```md
73-
### Your contact details
49+
### What's your favorite dish?
7450

75-
51+
Pizza
7652

77-
### What happened?
53+
### What's your preferred color?
7854

79-
A bug happened!
55+
- [x] Red
56+
- [ ] Green
57+
- [x] Blue
58+
```
8059
81-
### Version
60+
The actions output will be
8261
83-
1.0.0
62+
```json
63+
{
64+
"favorite_dish": "Pizza",
65+
"favorite_color": ["Red", "Blue"]
66+
}
67+
```
68+
69+
## Action outputs
8470

85-
### What browsers are you seeing the problem on?
71+
- `jsonString` - The entire output
72+
- `issueparser_<field_id>` - Access individual values
8673

87-
Chrome, Safari
8874

89-
### What else?
75+
Please take a look at GitHub's [Good practices for mitigating script injection attacks](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#good-practices-for-mitigating-script-injection-attacks) when using inline scripts. The examples blow are safe because they use intermediate environment variable as suggested by GitHub.
9076

91-
- [x] Never give up
92-
- [ ] Hot Dog is a Sandwich
77+
```yaml
78+
- run: echo $JSON_STRING > output.json
79+
env:
80+
JSON_STRING: ${{ steps.issue-parser.outputs.jsonString }}
9381
```
9482
95-
The actions output will be
9683
97-
```json
98-
{
99-
"contact": "[email protected]",
100-
"what_happened": "A bug happened!",
101-
"version": "1.0.0",
102-
"browsers": "Chrome, Safari",
103-
"what_else": ["Never give up"]
104-
}
84+
```yaml
85+
- run: echo $FAV_DISH
86+
env:
87+
FAV_DISH: ${{ steps.issue-parser.outputs.issueparser_favorite_dish }}
10588
```
10689
107-
10890
Want to learn more about this concept? Check out the [Codeless Contributions with GitHub Issue Forms](https://stefanbuck.com/blog/codeless-contributions-with-github-issue-forms) post on my blog.
10991
11092

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ branding:
66
inputs:
77
template-path:
88
description: 'Path to the issue form template file'
9+
issue-body:
10+
required: true
11+
description: 'Issue body to parse'
912
outputs:
1013
jsonString:
1114
description: 'JSON string'
1215
runs:
13-
using: 'node12'
16+
using: 'node16'
1417
main: 'dist/index.js'

fixtures/blank/issue.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"contact": "[email protected]",
3+
"what_happened": "A bug happened!",
4+
"version": "1.0.0",
5+
"browsers": "Chrome, Safari",
6+
"anything_else": ["Never give up"],
7+
"second_anything_else": ["Hot Dog is a Sandwich", "Another item"],
8+
"checkbox_without_an_id": []
9+
}

fixtures/full-example/form.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
body:
2+
- type: input
3+
id: contact
4+
attributes:
5+
label: Your contact details
6+
validations:
7+
required: true
8+
9+
- type: input
10+
id: what_happened
11+
attributes:
12+
label: What happened?
13+
validations:
14+
required: true
15+
16+
- type: input
17+
id: version
18+
attributes:
19+
label: Version
20+
validations:
21+
required: true
22+
23+
- type: input
24+
id: browsers
25+
attributes:
26+
label: What browsers are you seeing the problem on?
27+
validations:
28+
required: true
29+
30+
- type: checkboxes
31+
id: anything_else
32+
attributes:
33+
label: What else?
34+
options:
35+
- label: Never give up
36+
- label: Hot Dog is a Sandwich
37+
38+
- type: checkboxes
39+
id: second_anything_else
40+
attributes:
41+
label: And with that?
42+
options:
43+
- label: Never give up
44+
- label: Hot Dog is a Sandwich
45+
- label: Another item
46+
47+
- type: checkboxes
48+
attributes:
49+
label: Checkbox without an id?
50+
options:
51+
- label: IDs are great
52+
- label: IDs are bad
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
### Your contact details
2+
3+
4+
5+
### What happened?
6+
7+
A bug happened!
8+
9+
### Version
10+
11+
1.0.0
12+
13+
### What browsers are you seeing the problem on?
14+
15+
Chrome, Safari
16+
17+
### What else?
18+
19+
- [x] Never give up
20+
- [ ] Hot Dog is a Sandwich
21+
22+
### And with that?
23+
24+
- [] Never give up
25+
- [X] Hot Dog is a Sandwich
26+
- [x] Another item
27+
28+
### Checkbox without an id?
29+
30+
- [ ] IDs are great
31+
- [ ] IDs are bad

fixtures/full-example/issue.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { resolve } = require("path");
2+
const { readFileSync } = require("fs");
3+
4+
const issueBodyPath = resolve(__dirname, "issue-body.md");
5+
6+
module.exports = readFileSync(issueBodyPath, "utf-8");

fixtures/multiple-paragraphs/issue.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ const { readFileSync } = require("fs");
33

44
const issueBodyPath = resolve(__dirname, "issue-body.md");
55

6-
module.exports = {
7-
issue: {
8-
body: readFileSync(issueBodyPath, "utf-8"),
9-
},
10-
};
6+
module.exports = readFileSync(issueBodyPath, "utf-8")
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"contact": "[email protected]",
3-
"what_happened": "A bug happened!",
4-
"version": "1.0.0",
5-
"browsers": "Chrome, Safari",
6-
"anything_else": ["Never give up"],
7-
"second_anything_else": ["Hot Dog is a Sandwich", "Another item"],
8-
"checkbox_without_an_id": []
2+
"favorite_dish": "Pizza",
3+
"favorite_color": ["Red", "Blue"]
94
}

0 commit comments

Comments
 (0)