Self Link previews not showing for private sites?

AI-generated summary

Users reported that self-link previews (oneboxing) fail on private Discourse instances, displaying only the URL instead of the expected preview. Joey_Tuan noted this occurs on private instances, and codinghorror confirmed that private URLs behind login cannot onebox normally. techAPJ reproduced the issue, identifying that private hosted instances incorrectly use WhitelistedGenericOnebox instead of the DiscourseLocalOnebox engine. michael2 and Falco confirmed the bug on their setups. Falco discovered the root cause was related to config.relative_url_root in subfolder installations, where recognize_path failed to parse the path correctly. He proposed a code fix to strip Discourse.base_uri from the URI path before recognition. Although Falco submitted a PR, techAPJ noted the issue persisted on private hosted instances. Finally, zogstrip confirmed the issue was resolved in a subsequent commit.

My link preview is just showing the URL and no link preview. Note: my website is a private instance. Any suggestions to get this working?

إعجاب واحد (1)

Private urls behind login cannot onebox.

إعجابَين (2)

Is it possible to turn it off completely then, so I can show the full link?

Does it actually render like that if you post it though?

Yup it renders exactly like that.

Can you repro this @techapj? We should not render a busted onebox when a password protected site oneboxes itself.

3 إعجابات

Yes I can repro this, but only on private (login required) hosted instances.

The correct oneboxing behaviour in case of private instances is that the post gets oneboxed using local onebox class, but in case of private hosted instances this is not happening (it’s using WhitelistedGenericOnebox class instead).

I am looking into this issue and will post here with more updates.

7 إعجابات

This issue is also affecting me. We are running the latest Discourse, using the standard Docker container on a Digital Ocean Ubuntu droplet.

إعجاب واحد (1)

I have a login required and I’m seeing this too.

If your queue is too long could you give me any directions to craft a PR?

إعجابَين (2)

Thanks Rafael!

The underlying issue is that in case of some Discourse instances (private hosted in my experience) the DiscourseLocalOnebox engine is not being used (which is responsible for oneboxing internal topics/posts)

https://github.com/discourse/discourse/blob/master/lib/onebox/engine/discourse_local_onebox.rb#L6

I can’t figure out why in some cases the above engine is not being used, will appreciate your help with this.

إعجاب واحد (1)

Hey @techAPJ, good and bad news!

First, the good news: It’s working on my instance.

Second: Looks like the rails method recognize_path doesn’t play along with rails config.relative_url_root. So my bug wasn’t related with being private at all. Maybe this is @Joey_Tuan case?

So, it’s a subfolder :bug: after all :smile: (I stump on subfolder bugs even when I’m looking somewhere else).

If we want to fix it at Discourse level we need:

diff --git a/lib/onebox/engine/discourse_local_onebox.rb b/lib/onebox/engine/discourse_local_onebox.rb
index 5fd4897..5e3b797 100644
--- a/lib/onebox/engine/discourse_local_onebox.rb
+++ b/lib/onebox/engine/discourse_local_onebox.rb
@@ -14,7 +14,7 @@ module Onebox
         if other.kind_of?(URI)
           uri = other
           begin
-            route = Rails.application.routes.recognize_path(uri.path)
+            route = Rails.application.routes.recognize_path(uri.path.sub(Discourse.base_uri, ""))
             case route[:controller]
             when 'uploads'
               super
@@ -34,7 +34,7 @@ module Onebox
 
       def to_html
         uri = URI::parse(@url)
-        route = Rails.application.routes.recognize_path(uri.path)
+        route = Rails.application.routes.recognize_path(uri.path.sub(Discourse.base_uri, ""))
         url = @url.sub(/[&?]source_topic_id=(\d+)/, "")
         source_topic_id = $1.to_i

And we have local oneboxing at subfolder install working.

5 إعجابات

Thanks Rafael! Awesome work :+1:

Can you send a PR with your fix? I’ll deploy and verify on private hosted Discourse instances.

3 إعجابات

https://github.com/discourse/discourse/pull/3991

PS.: Should this be fixed upstream on rails?

4 إعجابات

Just checked, this issue can still be reproduced on private (login required) hosted instances. :disappointed:

Should be fixed now :banana:

https://github.com/discourse/discourse/commit/a655e4b09259fa5a908416b0add303d7c710ac1f

5 إعجابات

This topic was automatically closed after 24 hours. New replies are no longer allowed.