-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
139 lines (101 loc) · 3.5 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// semgrep-rules/javascript/express/security/express-puppeteer-injection.js
const express = require('express')
const app = express()
const port = 3000
const puppeteer = require('puppeteer')
const path = require('path');
// http://localhost:3000/?name=softreck.com
// http://localhost:3000/softreck.com
// http://localhost:3000/create/softreck.com
// http://webscreen.pl:3000/png/softreck.com
app.get('/create/:domain', async (req, res) => {
const browser = await puppeteer.launch({
headless: true,
ignoreDefaultArgs: ['--disable-extensions'],
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage()
// ruleid: express-puppeteer-injection
// const url = `https://${req.query.url}`
const url = `https://${req.params.domain}`
await page.goto(url)
var img = 'img/' + req.params.domain + '.png';
await page.screenshot({path: img})
await browser.close()
// absolute path to the file
let p = path.join(__dirname, img);
// send a png file
res.sendFile(p);
// res.send('Hello World!')
})
// http://localhost:3000/read/softreck.com
app.get('/read/:domain', async (req, res) => {
var img = 'png/' + req.params.domain + '.png';
// absolute path to the file
let p = path.join(__dirname, img);
// send a png file
res.sendFile(p);
// res.send('Hello World!')
})
/*
app.post('/test', async (req, res) => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// ruleid: express-puppeteer-injection
await page.setContent(`${req.body.foo}`)
await page.screenshot({path: 'example.png'})
await browser.close()
res.send('Hello World!')
})
const controller = async (req, res) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// ruleid: express-puppeteer-injection
const body = req.body.foo;
await page.setContent('<html>' + body + '</html>');
await page.screenshot({path: 'example.png'});
await browser.close();
res.send('Hello World!');
}
app.post('/test2', async (req, res) => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
// ruleid: express-puppeteer-injection
await page.evaluateOnNewDocument(`${req.body.foo}`)
await page.screenshot({path: 'example.png'})
await browser.close()
res.send('Hello World!')
})
const controller2 = async (req, res) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// ruleid: express-puppeteer-injection
const body = req.body.foo;
await page.evaluate('alert(' + body + ')');
await page.screenshot({path: 'example.png'});
await browser.close();
res.send('Hello World!');
}
app.post('/test2', controller)
/*
app.post('/ok-test', async (req, res) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// ok
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});
await browser.close();
res.send('Hello World!');
})
const controller = async (req, res) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// ok
const body = '<div>123</div>';
await page.setContent('<html>' + body + '</html>');
await page.screenshot({path: 'example.png'});
await browser.close();
res.send('Hello World!');
}*/
// app.post('/ok-test2', controller)
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))