Link to own domain results in "Internal Server Error"

Hi,

currently we are using Discourse v2.3.2 and we’ve faced a weird issue. If I create a topic or post with a link to the domain of the forum (without a path) I’m unable to save because of an Internal Server Error.

Let’s say my forums URL is https://www.my-forum.com and I post something like:
Please have a look on our [homepage](https://www.my-forum.com)

The result is the following:

As soon as I edit the link to […] [homepage](https://www.my-forum.com/latest) or […] [homepage](https://www.my-forum.com/categories) everything is working fine.

Here are the logs:

Message (21 copies reported)

NoMethodError (undefined method `split' for nil:NilClass)
/var/www/discourse/lib/auth/default_current_user_provider.rb:54:in `current_user'

Backtrace

/var/www/discourse/lib/auth/default_current_user_provider.rb:54:in 'current_user'
/var/www/discourse/lib/homepage_constraint.rb:12:in 'matches?'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/mapper.rb:40:in 'block in matches?'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/mapper.rb:39:in 'all?'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/mapper.rb:39:in 'matches?'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb:869:in 'block in recognize_path_with_request'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb:75:in 'block in recognize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb:68:in 'each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb:68:in 'recognize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb:859:in 'recognize_path_with_request'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb:855:in 'recognize_path'
/var/www/discourse/lib/discourse.rb:299:in 'route_for'
/var/www/discourse/app/models/topic_link.rb:182:in 'ensure_entry_for'
/var/www/discourse/app/models/topic_link.rb:130:in 'block (2 levels) in extract_from'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in 'transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:212:in 'transaction'
/var/www/discourse/app/models/topic_link.rb:128:in 'block in extract_from'
/var/www/discourse/app/models/topic_link.rb:126:in 'each'
/var/www/discourse/app/models/topic_link.rb:126:in 'extract_from'
/var/www/discourse/lib/post_creator.rb:559:in 'extract_links'
/var/www/discourse/lib/post_creator.rb:177:in 'block in create'
/var/www/discourse/lib/post_creator.rb:357:in 'block (2 levels) in transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in 'block in transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:239:in 'block in within_new_transaction'
/usr/local/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in 'mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/transaction.rb:236:in 'within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in 'transaction'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/transactions.rb:212:in 'transaction'
/var/www/discourse/lib/post_creator.rb:356:in 'block in transaction'
/var/www/discourse/lib/distributed_mutex.rb:42:in 'synchronize'
/var/www/discourse/lib/distributed_mutex.rb:12:in 'synchronize'
/var/www/discourse/lib/post_creator.rb:355:in 'transaction'
/var/www/discourse/lib/post_creator.rb:171:in 'create'
/var/www/discourse/lib/new_post_manager.rb:248:in 'perform_create_post'
/var/www/discourse/lib/new_post_manager.rb:191:in 'perform'
/var/www/discourse/app/controllers/posts_controller.rb:188:in 'create'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/basic_implicit_render.rb:6:in 'send_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/base.rb:194:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/rendering.rb:30:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/callbacks.rb:42:in 'block in process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:132:in 'run_callbacks'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/callbacks.rb:41:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/rescue.rb:22:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/instrumentation.rb:34:in 'block in process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb:168:in 'block in instrument'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications/instrumenter.rb:23:in 'instrument'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/notifications.rb:168:in 'instrument'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/instrumentation.rb:32:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal/params_wrapper.rb:256:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activerecord-5.2.3/lib/active_record/railties/controller_runtime.rb:24:in 'process_action'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/abstract_controller/base.rb:134:in 'process'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionview-5.2.3/lib/action_view/rendering.rb:32:in 'process'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/mini_profiler/profiling_methods.rb:78:in 'block in profile_method'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal.rb:191:in 'dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_controller/metal.rb:252:in 'dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb:52:in 'dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb:34:in 'serve'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb:52:in 'block in serve'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb:35:in 'each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/router.rb:35:in 'serve'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/routing/route_set.rb:840:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-protection-2.0.5/lib/rack/protection/frame_options.rb:31:in 'call'
/var/www/discourse/lib/middleware/omniauth_bypass_middleware.rb:32:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/tempfile_reaper.rb:15:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/conditional_get.rb:38:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/head.rb:12:in 'call'
/var/www/discourse/lib/content_security_policy/middleware.rb:12:in 'call'
/var/www/discourse/lib/middleware/anonymous_cache.rb:220:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/session/abstract/id.rb:232:in 'context'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/session/abstract/id.rb:226:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/cookies.rb:670:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb:28:in 'block in call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:98:in 'run_callbacks'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb:26:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:61:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/show_exceptions.rb:33:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/logster-2.3.0/lib/logster/middleware/reporter.rb:30:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/rack/logger.rb:38:in 'call_app'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/rack/logger.rb:28:in 'call'
/var/www/discourse/config/initializers/100-quiet_logger.rb:18:in 'call'
/var/www/discourse/config/initializers/100-silence_logger.rb:31:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/remote_ip.rb:81:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/request_id.rb:27:in 'call'
/var/www/discourse/lib/middleware/enforce_hostname.rb:17:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:14:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-mini-profiler-1.0.2/lib/mini_profiler/profiler.rb:171:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/message_bus-2.2.0/lib/message_bus/rack/middleware.rb:57:in 'call'
/var/www/discourse/lib/middleware/request_tracker.rb:163:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/engine.rb:524:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/railtie.rb:190:in 'public_send'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/railtie.rb:190:in 'method_missing'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/urlmap.rb:68:in 'block in call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/urlmap.rb:53:in 'each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/urlmap.rb:53:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/configuration.rb:227:in 'call'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:660:in 'handle_request'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:474:in 'process_client'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/server.rb:334:in 'block in run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in 'block in spawn_thread'

Env

hostname	[d585a64b75c4, 63b1df94653a]
process_id	11230
application_version	af192ff9d576abd451b30dc3dcbafa1d2b52a254
HTTP_HOST	beta.wer-weiss-was.de
REQUEST_URI	/posts
REQUEST_METHOD	POST
HTTP_USER_AGENT	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
HTTP_ACCEPT	application/json, text/javascript, */*; q=0.01
HTTP_REFERER	https://beta.wer-weiss-was.de/t/topic-slug/1234567/37
HTTP_X_FORWARDED_FOR	123.123.123.123:12345, 123.123.123.123
HTTP_X_REAL_IP	123.123.123.123
username	my-username

params	
raw	Text containing the link to the tld without path
unlist_topic	false
category	603
topic_id	1234567
is_warning	false
whisper	false
archetype	regular
typing_duration_msecs	77700
composer_open_duration_msecs	15485
featured_link	
shared_draft	false
reply_to_post_number	39
nested_post	true

Would be great if someone has an idea why this happens.

Kind Regards
Sascha Hofmann

As you posted, code is looking for a path after the domain.

Maybe a trailing slash would make it happy?
[homepage](https://www.my-forum.com/)

Unfortunately not. Good thought but it would’ve surprised me. Especially as any other URL works pretty well without a trailing slash like [homepage](https://google.com).

Are you running any third-party plugins?

Hi,

sorry for my late reply.
Yes we’re using some (third-party) plugins. These are the following:
discourse-adplugin
discourse-solved
discourse-user-notes
procourse-static-pages
and some self-developed ones which we’ve disabled already.

Hi,

just to finish this up. We’ve found the error in a patch we’ve applied. We had the same issue like described in this topic as we are using Azure Application Gateway V1.
In this post I described what we’ve did to work around this issue.

Anyway. It seems that request.ip is nil if you create a link to your own hostname so our workaround fails We’ve fixed it by wrapping it into a begin…rescue…end like this:

begin
  ip_port_split = request.ip.split(':')
  ip_only = ip_port_split.first
rescue
  ip_only = request.ip
end

We’re looking forward for the next rack update/release as it should/will handle those x-forwarded-for - headers correctly.

Thanks for your time and kind regards.
Sascha

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.