File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { getScreenshot } from "./_lib/puppeteer";
22
33module . exports = async ( req , res ) => {
44 if ( ! req . query . url ) return res . status ( 400 ) . send ( "No url query specified." ) ;
5+ if ( ! checkUrl ( req . query . url , req . hostname ) ) return res . status ( 400 ) . send ( "Invalid url query specified." ) ;
56 try {
67 const file = await getScreenshot ( req . query . url , req . query . width , req . query . height ) ;
78 res . setHeader ( "Content-Type" , "image/png" ) ;
@@ -12,3 +13,14 @@ module.exports = async (req, res) => {
1213 res . status ( 500 ) . send ( "The server encountered an error. You may have inputted an invalid query." ) ;
1314 }
1415}
16+
17+ function checkUrl ( string , hostname ) {
18+ var url = "" ;
19+ try {
20+ url = new URL ( string ) ;
21+ } catch ( error ) {
22+ return false ;
23+ }
24+ if ( url . hostname == hostname ) return false ;
25+ return true ;
26+ }
You can’t perform that action at this time.
0 commit comments