processone / processone/ejabberd

HTTP upload broken when public PUT URL path differs from request_handler definition

Open
#4,060 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Erlang
Stars
6.7k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Environment

  • ejabberd version: 23.01
  • Erlang version: Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 13.1.5
  • OS: Linux (Devuan)
  • Installed from: distro package

Configuration (only if needed): grep -Ev '^$|^\s*#' ejabberd.yml

listen:
  -
    port: 5280
    ip: "::1"
    transport: tcp
    module: ejabberd_http
    request_handlers:
      /upload: mod_http_upload
      /.well-known/host-meta: mod_host_meta
      /.well-known/host-meta.json: mod_host_meta
modules:
  mod_http_upload:
    hosts:
      - upload.@HOST@
    access: local
    get_url: "https://upload.@HOST@/"
    put_url: "https://upload.@HOST@/"
    docroot: "@HOME@/upload"
    dir_mode: "0750"
    file_mode: "0644"
    rm_on_unregister: true
    jid_in_url: sha1
    thumbnail: false
    custom_headers:
      "Access-Control-Allow-Origin": "https://upload.@HOST@/"
      "Access-Control-Allow-Methods": "GET,HEAD,PUT,OPTIONS"
      "Access-Control-Allow-Headers": "Content-Type"

Errors from error.log/crash.log

2023-07-05 18:09:22.480526+02:00 [info] <0.390.0>@ejabberd_listener:accept/7:273 (<0.576.0>) Accepted connection hidden_by_ejabberd -> [::1]:5280
2023-07-05 18:09:22.481919+02:00 [debug] <0.576.0>@ejabberd_http:init/3:129 S: [{[<<"upload">>],mod_http_upload},
    {[<<".well-known">>,<<"host-meta">>],mod_host_meta},
    {[<<".well-known">>,<<"host-meta.json">>],mod_host_meta}]

2023-07-05 18:09:22.483200+02:00 [debug] <0.576.0>@ejabberd_http:process_header/2:290 (#Port<0.44>) http query: 'PUT' <<"/upload/01a66df340fbde62dc61c6746f33783061170e87/ZR7WpuNlK22WQhj3GVWoTouTBF2btSE9QnxEdl9E/20221221_201620_20221223230532.jpg">>

2023-07-05 18:09:22.484977+02:00 [debug] <0.576.0>@ejabberd_http:process/1:362 [<<"upload">>,<<"01a66df340fbde62dc61c6746f33783061170e87">>,
 <<"ZR7WpuNlK22WQhj3GVWoTouTBF2btSE9QnxEdl9E">>,
 <<"20221221_201620_20221223230532.jpg">>] matches [<<"upload">>]
2023-07-05 18:09:22.486212+02:00 [warning] <0.576.0>@mod_http_upload:process/2:570 Cannot handle PUT request from hidden_by_ejabberd for upload.example.com: Upload not configured for this host

Bug description

To have beautiful HTTP URLs for the HTTP upload file transfer module I have installed a web server in front of ejabberd which takes requests on https://upload.example.com/ and forwards them to ejabberd's local port (http://[::1]:5280/upload/).

ejabberd prints the misleading error message Upload not configured for this host when the path of the request does not match the one configured in mod_http_upload's put_url.

Creating a separate local port whose only request_handler is /: mod_http_upload HTTP uploads work as expected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the request routing and upload handling shown in ejabberd_http:process/1 and mod_http_upload:process/2, then compare the configured request-handler path with put_url. Reproduce the proxied PUT request and verify that a differing public path no longer produces the misleading “Upload not configured for this host” result; add or update a regression test if the relevant test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.