The vulnerability is Server-Side Request Forgery (SSRF)php // vulnerable code $_GET['url']; $content = file_get_contents($url); echo $content; ?> ``` ```html Web App Example ``` ```php // solution how to fix the vulnerable code
php
// solution how to fix the vulnerable code
<?phpfunctionis_valid_url($url){if(filter_var($url,FILTER_VALIDATE_URL)===false){returnfalse;}$parsed_url=parse_url($url);if(($parsed_url['scheme']!=='http')&&($parsed_url['scheme']!=='https')){returnfalse;}if($parsed_url['host']==='localhost'||$parsed_url['host']==='127.0.0.1'){returnfalse;}// Add further validation checks as neededreturntrue;}$url=$_GET['url'];if(is_valid_url($url)){$content=file_get_contents($url);echo$content;}else{echo"Invalid URL";}