| | <?php |
| | require_once __DIR__ . '/config.php'; |
| | +require_once __DIR__ . '/security.php'; |
| | |
| | require_once __DIR__ . '/includes/git_functions.php'; |
| | require_once __DIR__ . '/includes/repo_functions.php'; |
| | require_once __DIR__ . '/includes/helpers.php'; |
| | |
| | $action = $_GET['action'] ?? 'list'; |
| | -$repo = $_GET['repo'] ?? ''; |
| | +$repo = sanitizeRepoName($_GET['repo'] ?? ''); |
| | $ref = $_GET['ref'] ?? 'HEAD'; |
| | -$path = $_GET['path'] ?? ''; |
| | -$hash = $_GET['hash'] ?? ''; |
| | +$path = sanitizePath($_GET['path'] ?? ''); |
| | +$hash = sanitizeHash($_GET['hash'] ?? ''); |
| | + |
| | +$allowed_actions = ['list', 'repo', 'commit', 'blob', 'raw']; |
| | + |
| | +if (!in_array($action, $allowed_actions, true)) { |
| | + $action = 'list'; |
| | +} |
| | |
| | +$allowed_themes = ['dark', 'light']; |
| | $current_theme = $_GET['theme'] ?? 'dark'; |
| | + |
| | +if (!in_array($current_theme, $allowed_themes, true)) { |
| | + $current_theme = 'dark'; |
| | +} |
| | + |
| | $css_file = ($current_theme === 'dark') ? 'dark.css' : 'light.css'; |
| | |
| | if ($action === 'raw' && !empty($repo) && !empty($hash)) { |
| | - $name = $_GET['name'] ?? 'file'; |
| | - $content = getBlobBinary($repo, $hash); |
| | + $repoPath = REPOS_PATH . '/' . $repo; |
| | + if (!is_dir($repoPath)) { |
| | + http_response_code(404); |
| | + exit('Repository not found'); |
| | + } |
| | |
| | - header('Content-Type: application/octet-stream'); |
| | - header('Content-Disposition: attachment; filename="' . $name . '"'); |
| | - header('Content-Length: ' . strlen($content)); |
| | - echo $content; |
| | + $name = sanitizeFilename($_GET['name'] ?? 'file'); |
| | + |
| | + try { |
| | + $content = getBlobBinary($repo, $hash); |
| | + |
| | + header('Content-Type: application/octet-stream'); |
| | + header('Content-Disposition: attachment; filename="' . $name . '"'); |
| | + header('Content-Length: ' . strlen($content)); |
| | + header('X-Content-Type-Options: nosniff'); |
| | + echo $content; |
| | + } catch (Exception $e) { |
| | + http_response_code(404); |
| | + exit('File not found'); |
| | + } |
| | + |
| | exit; |
| | } |
| | |
| | -$page_title = $action === 'list' ? SITE_TITLE : htmlspecialchars($repo) . ' - ' . SITE_TITLE; |
| | +$page_title = $action === 'list' |
| | + ? SITE_TITLE |
| | + : htmlspecialchars($repo, ENT_QUOTES, 'UTF-8') . ' - ' . SITE_TITLE; |
| | |
| | include __DIR__ . '/views/header.php'; |
 |
| | |
| | include __DIR__ . '/views/footer.php'; |
| | - |
| | |