Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Fedosov committed May 11, 2024
1 parent 0773216 commit 51bd3b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
11 changes: 3 additions & 8 deletions vulnerabilities/open_redirect/source/high.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?php

if (array_key_exists ("redirect", $_GET) && $_GET['redirect'] != "") {
if (!empty($_GET['redirect'])) {
if (strpos($_GET['redirect'], "info.php") !== false) {
header ("location: " . $_GET['redirect']);
exit;
} else {
http_response_code (500);
?>
<p>You can only redirect to the info page.</p>
<?php
echo "You can only redirect to the info page.";
exit;
}
}

http_response_code (500);
?>
<p>Missing redirect target.</p>
<?php
echo "Missing redirect target.";
exit;
?>
40 changes: 17 additions & 23 deletions vulnerabilities/open_redirect/source/impossible.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
<?php

$target = "";
$redirects = [
1 => "info.php?id=1",
2 => "info.php?id=2",
99 => "https://digi.ninja",
];

if (array_key_exists ("redirect", $_GET) && is_numeric($_GET['redirect'])) {
switch (intval ($_GET['redirect'])) {
case 1:
$target = "info.php?id=1";
break;
case 2:
$target = "info.php?id=2";
break;
case 99:
$target = "https://digi.ninja";
break;
}
if ($target != "") {
header ("location: " . $target);
exit;
} else {
?>
Unknown redirect target.
<?php
exit;
}
if (!empty($_GET['redirect'])) {
$redirectId = $_GET['redirect'];
$target = $redirects[$redirectId] ?? "";
if ($target !== "") {
header("Location: " . $target);
exit;
} else {
echo "Unknown redirect target.";
exit;
}
}

echo "Missing redirect target.";
exit;
?>
Missing redirect target.
6 changes: 2 additions & 4 deletions vulnerabilities/open_redirect/source/low.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php

if (array_key_exists ("redirect", $_GET) && $_GET['redirect'] != "") {
if (!empty($_GET['redirect'])) {
header ("location: " . $_GET['redirect']);
exit;
}

http_response_code (500);
?>
<p>Missing redirect target.</p>
<?php
echo "Missing redirect target.";
exit;
?>
10 changes: 3 additions & 7 deletions vulnerabilities/open_redirect/source/medium.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

if (array_key_exists ("redirect", $_GET) && $_GET['redirect'] != "") {
if (!empty($_GET['redirect'])) {
if (preg_match ("/http:\/\/|https:\/\//i", $_GET['redirect'])) {
http_response_code (500);
?>
<p>Absolute URLs not allowed.</p>
<?php
echo "Absolute URLs not allowed.";
exit;
} else {
header ("location: " . $_GET['redirect']);
Expand All @@ -14,8 +12,6 @@
}

http_response_code (500);
?>
<p>Missing redirect target.</p>
<?php
echo "Missing redirect target.";
exit;
?>

0 comments on commit 51bd3b3

Please sign in to comment.