Skip to content
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

Avoid requests to opengraph image if no host detected #38645

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

julien-nc
Copy link
Member

When using the LinkReferenceProvider to resolve https://www.compart.com/en/unicode/U+033C, for example, the OpenGraph image URI is /en/unicode/images/icon/icon-compart.svg. It is kind of fine because our HTTP client refuses to make requests when there is no host.

We might want to improve this.
With this PR, we don't make a request if no host is detected.

Maybe we even want to forbid local addresses regardless of the allow_local_remote_servers system config. What do you think?

PS: The "previews and thumbnails" label is not exactly appropriate but it's the most fitting 😁

$folder->newFile(md5($reference->getId()), $bodyStream->getContents());
$reference->setImageUrl($this->urlGenerator->linkToRouteAbsolute('core.Reference.preview', ['referenceId' => md5($reference->getId())]));
$host = parse_url($object->images[0]->url, PHP_URL_HOST);
if ($host === false || $host === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return early to avoid indentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that on purpose to avoid creating issues if we ever append something to this method and forget about the early return.

@julien-nc julien-nc force-pushed the enh/noid/link-ref-provider-local-image-uri branch 2 times, most recently from 28f0fc6 to 198b681 Compare June 6, 2023 09:31
@ChristophWurst ChristophWurst added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jun 6, 2023
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc julien-nc force-pushed the enh/noid/link-ref-provider-local-image-uri branch from 198b681 to 3621a6b Compare June 9, 2023 08:38
@juliushaertl juliushaertl merged commit 76d4487 into master Jun 9, 2023
@juliushaertl juliushaertl deleted the enh/noid/link-ref-provider-local-image-uri branch June 9, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish enhancement feature: previews and thumbnails
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants