/stats/ is publicly reachable although statistics are disabled #37

Open
opened 2026-11-15 11:40:55 +01:00 by stb · 0 comments
Owner

Summary

Statistics are switched off (USE_STATISTICS = false in web/www/sunders/config.php and data_handler/utils/config.php), but the stats page is still served at /stats/ and /<lang>/stats/ (de, en, es, fr, it, ru). The setting only hides the link on the map page (index.php:131); stats/index.php never checks it.

What happens

  • With the initial dump loaded (normal deployment): the page shows statistics from the statistics table in data_handler/data_init/sunders_6822255.sql. Because USE_STATISTICS is false, the data handler never updates that table, so the numbers are a frozen snapshot that silently diverges from the map.
  • Without a statistics table (database initialised without the dump, or the import failed): the page fails with an uncaught mysqli_sql_exception: Table 'camera.statistics' doesn't exist and returns HTTP 500. On images without php.ini-production, PHP's default display_errors sends the stack trace, including server file paths, to the visitor.
  • The page runs several GROUP BY queries over the whole statistics table on every request, unauthenticated and uncached.

Steps to reproduce

  1. Start the stack with docker compose up.
  2. Open http://localhost:8080/stats/ (or /en/stats/).
  3. You get either stale statistics or, without the table, an HTTP 500.

Expected

When statistics are disabled, /stats/ should not run any queries. It should return a 404 or redirect to the map.

Suggested fix

At the top of stats/index.php, after config.php is included:

if (!USE_STATISTICS) {
  http_response_code(404);
  exit;
}

If statistics should come back later, the statistics table also needs to be created by init_db.php and kept up to date by the data handler, and the page should handle database errors without a fatal error.

The security-fixes branch switches the web image to php.ini-production, so stack traces no longer reach visitors. The endpoint itself is unchanged there.

### Summary Statistics are switched off (`USE_STATISTICS = false` in `web/www/sunders/config.php` and `data_handler/utils/config.php`), but the stats page is still served at `/stats/` and `/<lang>/stats/` (`de`, `en`, `es`, `fr`, `it`, `ru`). The setting only hides the link on the map page ([index.php:131](web/www/sunders/index.php#L131)); `stats/index.php` never checks it. ### What happens - **With the initial dump loaded (normal deployment):** the page shows statistics from the `statistics` table in `data_handler/data_init/sunders_6822255.sql`. Because `USE_STATISTICS` is false, the data handler never updates that table, so the numbers are a frozen snapshot that silently diverges from the map. - **Without a `statistics` table** (database initialised without the dump, or the import failed): the page fails with an uncaught `mysqli_sql_exception: Table 'camera.statistics' doesn't exist` and returns HTTP 500. On images without `php.ini-production`, PHP's default `display_errors` sends the stack trace, including server file paths, to the visitor. - The page runs several `GROUP BY` queries over the whole `statistics` table on every request, unauthenticated and uncached. ### Steps to reproduce 1. Start the stack with `docker compose up`. 2. Open `http://localhost:8080/stats/` (or `/en/stats/`). 3. You get either stale statistics or, without the table, an HTTP 500. ### Expected When statistics are disabled, `/stats/` should not run any queries. It should return a 404 or redirect to the map. ### Suggested fix At the top of `stats/index.php`, after `config.php` is included: if (!USE_STATISTICS) { http_response_code(404); exit; } If statistics should come back later, the `statistics` table also needs to be created by `init_db.php` and kept up to date by the data handler, and the page should handle database errors without a fatal error. ### Related The `security-fixes` branch switches the web image to `php.ini-production`, so stack traces no longer reach visitors. The endpoint itself is unchanged there.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
CCCHH/sunders#37
No description provided.