-
Notifications
You must be signed in to change notification settings - Fork 5
Feat accessing CMS with token. #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
f47e4de
1a389dd
713b54c
f29c8b1
29fbdf7
9fa6248
b621915
48edf63
c044628
56b1bba
98caa6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace App\Http\Controllers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use App\Services\CmsClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use Illuminate\Http\Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class CmsProxyController extends Controller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private CmsClient $cmsClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function __construct(CmsClient $cmsClient) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->cmsClient = $cmsClient; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Generic proxy for CMS API requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * CSRF protection is automatically applied by Laravel's web middleware | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return \Illuminate\Http\Response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function proxy(Request $request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $endpoint = $request->input('endpoint'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+25
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | |
| $endpoint = $request->input('endpoint'); | |
| { | |
| // Define a whitelist of allowed endpoints | |
| $allowedEndpoints = [ | |
| 'articles', | |
| 'users', | |
| 'depict/2D', | |
| // Add other allowed endpoints here | |
| ]; | |
| $endpoint = $request->input('endpoint'); | |
| if (!in_array($endpoint, $allowedEndpoints, true)) { | |
| return response('Invalid endpoint', 400); | |
| } |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for failed API requests. If the CMS API returns an error or times out, the proxy will forward that error response to the client without any logging or fallback behavior. Consider adding try-catch blocks and logging failures for monitoring and debugging purposes.
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response status code is not preserved when the API request fails. The proxy always returns the CMS API's status code, but if the request throws an exception (timeout, network error), it will result in a 500 error without a proper error response. Consider wrapping the API call in a try-catch and returning an appropriate error status (e.g., 502 Bad Gateway) when the upstream service is unavailable.
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for failed API requests in the depict2D method. If the CMS API is unavailable or returns an error, users will see broken images without any fallback. Consider adding try-catch blocks and returning a placeholder image or appropriate error response on failure.
| $response = $this->cmsClient->get('depict/2D', $params); | |
| return response($response->body()) | |
| ->header('Content-Type', $response->header('Content-Type') ?? 'image/svg+xml') | |
| ->header('Cache-Control', 'public, max-age=86400'); | |
| try { | |
| $response = $this->cmsClient->get('depict/2D', $params); | |
| // If the response is not successful, return a placeholder image | |
| if ($response->status() !== 200) { | |
| return $this->placeholderImage(); | |
| } | |
| return response($response->body()) | |
| ->header('Content-Type', $response->header('Content-Type') ?? 'image/svg+xml') | |
| ->header('Cache-Control', 'public, max-age=86400'); | |
| } catch (\Exception $e) { | |
| // On exception, return a placeholder image | |
| return $this->placeholderImage(); | |
| } | |
| } | |
| /** | |
| * Returns a simple SVG placeholder image indicating an error. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| private function placeholderImage() | |
| { | |
| $svg = <<<SVG | |
| <svg xmlns="http://www.w3.org/2000/svg" width="120" height="40"> | |
| <rect width="120" height="40" fill="#eee"/> | |
| <text x="60" y="25" font-size="14" text-anchor="middle" fill="#888">Image Error</text> | |
| </svg> | |
| SVG; | |
| return response($svg) | |
| ->header('Content-Type', 'image/svg+xml') | |
| ->header('Cache-Control', 'public, max-age=300'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
CmsClient::get()method is being called with 3 arguments, but the method signature only accepts 2 parameters ($endpointand$params). The third argumentfalsewill be ignored. This appears to be a bug that needs to be fixed by updating theCmsClient::get()method signature to accept this third parameter.