Skip to content

Commit d5948a7

Browse files
Copilotvickyrolanda
andcommitted
Fix SSRF vulnerability by implementing URL validation in lastrelease function
Co-authored-by: vickyrolanda <[email protected]>
1 parent 2338bf5 commit d5948a7

File tree

7 files changed

+22845
-12
lines changed

7 files changed

+22845
-12
lines changed

app/Helpers/helper.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,60 @@ function fixDomainName($url = '')
114114
}
115115
}
116116

117+
if (! function_exists('is_trusted_github_api_url')) {
118+
/**
119+
* Validate that the URL is a trusted GitHub API endpoint to prevent SSRF attacks.
120+
*
121+
* @param string $url
122+
* @return bool
123+
*/
124+
function is_trusted_github_api_url($url)
125+
{
126+
// Parse the URL to validate its components
127+
$parsed = parse_url($url);
128+
129+
if (!$parsed || !isset($parsed['scheme'], $parsed['host'], $parsed['path'])) {
130+
return false;
131+
}
132+
133+
// Only allow HTTPS
134+
if ($parsed['scheme'] !== 'https') {
135+
return false;
136+
}
137+
138+
// Only allow api.github.com domain
139+
if ($parsed['host'] !== 'api.github.com') {
140+
return false;
141+
}
142+
143+
// Allow only specific trusted OpenSID repository release endpoints
144+
$allowed_paths = [
145+
'/repos/OpenSID/rilis-premium/releases/latest',
146+
'/repos/OpenSID/rilis-pbb/releases/latest',
147+
'/repos/OpenSID/opendk/releases/latest',
148+
'/repos/OpenSID/rilis-opensid-api/releases/latest',
149+
];
150+
151+
return in_array($parsed['path'], $allowed_paths, true);
152+
}
153+
}
154+
117155
if (! function_exists('lastrelease')) {
118156
/**
119-
* Validasi domain.
157+
* Get latest release from trusted GitHub API endpoints.
158+
*
159+
* Security: Only allows requests to trusted GitHub API endpoints to prevent SSRF attacks.
120160
*
121161
* @param string $url
122-
* @return object
162+
* @return object|false
123163
*/
124164
function lastrelease($url)
125165
{
166+
// Security: Validate that the URL is a trusted GitHub API endpoint
167+
if (!is_trusted_github_api_url($url)) {
168+
return false;
169+
}
170+
126171
try {
127172
$response = Http::withHeaders([
128173
'Accept' => 'application/vnd.github.v3+json',

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@playwright/test": "^1.54.1",
19-
"axios": "^0.28",
19+
"axios": "^0.30",
2020
"laravel-mix": "^6.0.6",
2121
"lodash": "^4.17.19",
2222
"postcss": "^8.1.14"

public/css/app.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)