Skip to content

Commit

Permalink
Merge pull request #12 from sillyangel/autofix/alert-1-e472fe2ba6
Browse files Browse the repository at this point in the history
Fix code scanning alert #1: Server-side request forgery
  • Loading branch information
sillyangel authored Sep 20, 2024
2 parents 62df70b + a1d5302 commit e15d93d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ app.use(express.static('public'));

app.get('/image', async (req, res) => {
const imageUrl = req.query.url;
const allowedDomains = ['playmusichtml.web.app', 'sillyangel.github.io']; // Add your trusted domains here
if (imageUrl) {
try {
const url = new URL(imageUrl);
if (!allowedDomains.includes(url.hostname)) {
return res.status(400).send('Invalid image URL domain.');
}
const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });
const contentType = response.headers['content-type'];
res.set('Content-Type', contentType);
Expand Down

0 comments on commit e15d93d

Please sign in to comment.