View Issue Details

This issue affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
20672Bug reportsInstallationpublic2026-09-21 21:59
Reportercoffee-jinn-2002 Assigned Toc_schmitz  
PrioritynoneSeverityminor 
Status closedResolutionfixed 
Summary20672: HTTP 400 "The requested hostname is invalid" does not mention allowed_hosts.php, leaving admins without a way to recover
Description

When a request arrives with a host name that is not listed in
application/config/allowed_hosts.php, LimeSurvey returns:

400: Bad Request - The requested hostname is invalid.
The request could not be understood by the server due to malformed
syntax. Please do not repeat the request without modifications.

The message does not mention allowed_hosts.php, the config directory, or
any way to fix the situation. An administrator who hits this has no
indication of what is wrong or where to look.

This matters because the allowed hosts file is created automatically, and
the only explanation is shown once and cannot be retrieved later.

In application/controllers/admin/Authentication.php (line 185 in
7.0.13+260903), on the first successful login LimeSurvey writes
allowed_hosts.php containing only the host used at that moment, and shows
a flash message:

"The allowed hosts file (application/config/allowed_hosts.php) has
 been created with "%s" as trusted host. For security reasons,
 LimeSurvey can only be accessed through that domain. If you need
 additional hosts, please edit the allowed hosts file directly."

That wording is clear and actionable. However it is a one-time flash
message. Once it is gone, the administrator has no way to see it again.

The exception itself is thrown in application/core/LSHttpRequest.php
(line 313 in 7.0.13+260903):

public static function checkIsAllowedHost($hostInfo)
{
    $host = parse_url($hostInfo, PHP_URL_HOST);
    if ($host && !App()->isHostAllowed($host)) {
        throw new CHttpException(400, gT("The requested hostname is invalid.", 'unescaped'));
    }
}

This is easy to run into with common deployment patterns:

  • Install with Docker and log in once through http://localhost:8080
    while setting things up, then put the instance behind a domain name.
  • Set up through an SSH tunnel or a reverse proxy, then switch to the
    public host name.

In both cases the first login writes "localhost" as the only trusted
host, and every later request through the real domain fails with the
generic 400 above.

I hit this while deploying LimeSurvey 7.0.11 in Docker behind nginx. I
had to read the source (LSHttpRequest.php, LSApplicationTrait.php) to
find out that allowed_hosts.php existed at all. An administrator who is
not comfortable reading PHP source would most likely be stuck.

Steps To Reproduce

Steps to reproduce

  1. Install LimeSurvey so that application/config/allowed_hosts.php does
    not exist yet (a fresh installation).
  2. Open the admin login through one host name, for example
    http://localhost:8080/index.php/admin, and log in successfully.
    -> allowed_hosts.php is created containing only "localhost".
  3. Access the same installation through a different host name, for
    example the server's domain name or its IP address.

Expected result

The error page tells the administrator which file controls this, so that
the problem can be fixed without reading the source code. For example:

The requested hostname is invalid. If this host should be allowed,
add it to application/config/allowed_hosts.php.

LimeSurvey already contains suitable wording in
application/controllers/admin/Authentication.php (line 185). Reusing the
reference to "application/config/allowed_hosts.php" in the exception
thrown at application/core/LSHttpRequest.php line 313 would be enough.

Actual result

A generic error page with no reference to allowed_hosts.php and no
instruction on how to add the new host:

400: Bad Request - The requested hostname is invalid.
The request could not be understood by the server due to malformed
syntax. Please do not repeat the request without modifications.

(See attached 400-invalid-hostname.html for the full response.)

TagsNo tags attached.
Bug heat10
Complete LimeSurvey version number (& build)7.0.11+260821
I will donate to the project if issue is resolvedNo
BrowserChrome
Database type & versionMariaDB 11.4
Server OS (if known)Debian (inside Docker container) on Rocky Linux 10 host
Webserver software & version (if known)Apache 2.4.68 (Debian), behind nginx 1.26.3 as reverse proxy
PHP Version8.5.10

Users monitoring this issue

coffee-jinn-2002

Activities

coffee-jinn-2002

coffee-jinn-2002

2026-09-06 06:39

reporter   ~85586

I am happy to prepare a pull request for this if the approach is acceptable.

coffee-jinn-2002

coffee-jinn-2002

2026-09-06 11:09

reporter   ~85587

Adding a screenshot of the error page.

The description refers to an HTML capture, but the saved HTML references
44 external CSS/JS files and therefore does not render correctly when
opened standalone. The attached screenshot shows what an administrator
actually sees.

400-invalid-hostname.png (46,202 bytes)   
400-invalid-hostname.png (46,202 bytes)   
DenisChenu

DenisChenu

2026-09-07 09:09

developer   ~85589

The error page tells the administrator which file controls this, so that

No, it's not for all user (and clearly not for hacker)
In my opinion, it must be logged as an error, showing instructions on how to fix (maybe new category for logguing).

Idea :

  1. Add at Yii::log("400 error due to invalid request, invalid hostname {$hostInfo} not found in allowedHosts config', 'error', 'application.limesurvey.core.LSHttpRequest.checkIsAllowedHost') at https://github.com/LimeSurvey/LimeSurvey/blob/81a170f618ca5395b9c9d57cd21ec60025720b03/application/core/LSHttpRequest.php#L313
  2. Add error log file : 'level'='error, 'categories' => 'application.limesurvey.*' in internal (limesurbey-error for name ?)
  3. Add "If you are administrator, you can check log file in runtime directory"
c_schmitz

c_schmitz

2026-09-07 09:31

administrator   ~85593

However, writing a log file to a public directory is a bad idea.

DenisChenu

DenisChenu

2026-09-07 09:37

developer   ~85594

However, writing a log file to a public directory is a bad idea.

We already do it for plugin.log

And not public if use apache (issue #20425 for example)

coffee-jinn-2002

coffee-jinn-2002

2026-09-09 09:07

reporter   ~85615

I am not sure which side is correct, sorry. But I tryed on my install
(7.0.11) and maybe this is useful.

Apache and nginx are different here. On my server (Apache behind nginx as
reverse proxy) the log is protected:

GET /tmp/runtime/plugin.log  -> 403

But nginx does not read .htaccess at all, so with PHP-FPM + nginx the same
file is just returned. The .htaccess comment also says "With a correct apache
configuration", so it depends on the setup.

My feeling, if I may say: I am a little afraid to depend on the web server
for this. Maybe CSysLogRoute is an option too? It is already in the bundled
Yii and it writes no file.

Anyway that is your decision. Can I prepare a pull request for the parts that
nobody disagree - the Yii::log() call, and keeping the 400 page generic with
one line to check the server log? Those do not depend on where the log goes.
If you want to fix the place first, I can wait, no problem.

DenisChenu

DenisChenu

2026-09-09 10:25

developer   ~85617

However, writing a log file to a public directory is a bad idea.

14637: New install : allow to set runtimePath at installer

@coffee-jinn-2002 maybe you do not have plugin installed and log error.

coffee-jinn-2002

coffee-jinn-2002

2026-09-09 11:51

reporter   ~85618

Thank you for 14637, I did not know it. That is exactly the place question,
and it is from 2019, so I think it is separate from this ticket.

About the plugin - yes, I have one (our own), so plugin.log exists here (438
bytes). It contains survey ids like "sid=358973 4/4", so 14637 makes a lot
of sense to me.

But I should also say the 403 is not really about the file. The .htaccess
denies the whole directory, so a name that does not exist gives 403 too:

/tmp/runtime/plugin.log                -> 403
/tmp/runtime/no-such-file-12345.log    -> 403

So on Apache it is protected even with no log file, and on nginx none of this
applies.

Then, can I make the pull request for the Yii::log() part and the generic
page text? The place can be decided in 14637, I think.

c_schmitz

c_schmitz

2026-09-17 00:13

administrator   ~85804

I don't like either solution.
What is the user story here? Under what circumstance would someone have a problem and not know what to do?
Could we maybe show a more elaborate message if debug mode is active?

LimeBot

LimeBot

2026-09-17 13:12

administrator   ~85808

Fixed in Release 7.1.2+260917

c_schmitz

c_schmitz

2026-09-19 22:43

administrator   ~85854

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=40385

Related Changesets

LimeSurvey: master 4a0e13d2

2026-09-17 10:26

c_schmitz


Details Diff
Fixed issue 20672: HTTP 400 "The requested hostname is invalid" does not give any details, even with active debug mode Affected Issues
20672
mod - application/core/LSHttpRequest.php Diff File

Issue History

Date Modified Username Field Change
2026-09-06 06:36 coffee-jinn-2002 New Issue
2026-09-06 06:39 coffee-jinn-2002 Note Added: 85586
2026-09-06 06:39 coffee-jinn-2002 Bug heat 0 => 2
2026-09-06 06:40 coffee-jinn-2002 Issue Monitored: coffee-jinn-2002
2026-09-06 06:40 coffee-jinn-2002 Bug heat 2 => 4
2026-09-06 11:09 coffee-jinn-2002 Note Added: 85587
2026-09-06 11:09 coffee-jinn-2002 File Added: 400-invalid-hostname.png
2026-09-07 09:09 DenisChenu Note Added: 85589
2026-09-07 09:09 DenisChenu Bug heat 4 => 6
2026-09-07 09:31 c_schmitz Note Added: 85593
2026-09-07 09:31 c_schmitz Bug heat 6 => 8
2026-09-07 09:37 DenisChenu Note Added: 85594
2026-09-09 09:07 coffee-jinn-2002 Note Added: 85615
2026-09-09 10:25 DenisChenu Note Added: 85617
2026-09-09 11:51 coffee-jinn-2002 Note Added: 85618
2026-09-17 00:13 c_schmitz Note Added: 85804
2026-09-17 13:12 LimeBot Note Added: 85808
2026-09-17 13:12 LimeBot Status new => closed
2026-09-17 13:12 LimeBot Resolution open => fixed
2026-09-17 13:12 LimeBot Bug heat 8 => 10
2026-09-19 22:43 c_schmitz Changeset attached => LimeSurvey master 4a0e13d2
2026-09-19 22:43 c_schmitz Note Added: 85854
2026-09-19 22:43 c_schmitz Assigned To => c_schmitz
2026-09-19 22:43 c_schmitz Status closed => resolved
2026-09-21 21:59 c_schmitz Status resolved => closed