2525namespace App \Services \InfoProviderSystem \Providers ;
2626
2727use App \Exceptions \ProviderIDNotSupportedException ;
28+ use App \Helpers \RandomizeUseragentHttpClient ;
2829use App \Services \AI \AIPlatformRegistry ;
2930use App \Services \InfoProviderSystem \DTOJsonSchemaConverter ;
3031use App \Services \InfoProviderSystem \DTOs \PartDetailDTO ;
3536use Symfony \AI \Platform \Message \Message ;
3637use Symfony \AI \Platform \Message \MessageBag ;
3738use Symfony \Component \DomCrawler \Crawler ;
39+ use Symfony \Component \HttpClient \NoPrivateNetworkHttpClient ;
3840use Symfony \Component \Intl \Languages ;
3941use Symfony \Contracts \HttpClient \HttpClientInterface ;
4042
@@ -55,12 +57,12 @@ public function __construct(
5557 private readonly AIPlatformRegistry $ AIPlatformRegistry ,
5658 private readonly DTOJsonSchemaConverter $ jsonSchemaConverter ,
5759 ) {
58- $ this -> httpClient = $ httpClient -> withOptions ([
59- ' timeout ' => 30 ,
60- ' headers ' => [
61- 'User-Agent ' => ' Mozilla/5.0 (compatible; Part-DB AI-Extractor/1.0) ' ,
62- ],
63- ] );
60+ //Use NoPrivateNetworkHttpClient to prevent SSRF vulnerabilities, and RandomizeUseragentHttpClient to make it harder for servers to block us
61+ $ this -> httpClient = ( new RandomizeUseragentHttpClient ( new NoPrivateNetworkHttpClient ( $ httpClient )))-> withOptions (
62+ [
63+ 'timeout ' => 15 ,
64+ ]
65+ );
6466 }
6567
6668 public function getProviderInfo (): array
@@ -199,7 +201,7 @@ private function callLLM(string $htmlContent, string $url, ?string $structuredDa
199201 $ result = $ aiPlatform ->invoke ($ this ->settings ->model ?? throw new \RuntimeException ('No model selected ' ), $ input , [
200202 'response_format ' => [
201203 'type ' => 'json_schema ' ,
202- 'json_schema ' => $ this ->jsonSchemaConverter ->getJSONSchema (),
204+ 'json_schema ' => $ this ->jsonSchemaConverter ->getJSONSchema (),
203205 ]
204206 ]);
205207 } catch (\Throwable $ e ) {
0 commit comments