#1843·visdom

/upload_env persists an unvalidated environment, which then 500s on every open and compare

Author: tarone-saloniCreated Sep 19, 2026Updated Sep 19, 2026

Bug Description

Environment files are only checked for the presence of jsons and reload. Their actual types are not validated.

The server expects an environment to have this structure:

json
{
  "jsons": {
    "win_id": {
      ...
    }
  },
  "reload": {
    ...
  }
}

However, the current validation also accepts malformed values such as:

json
{"jsons": [], "reload": {}}

or:

json
{"jsons": null, "reload": {}}

or:

json
{"jsons": {"w1": "not a pane"}, "reload": {}}

These environments are accepted by /upload_env, stored in state, written to disk, and broadcast to connected clients. Later, when the environment is opened or compared, the server assumes jsons is a mapping and crashes with an uncaught AttributeError.

For example:

POST /env/<eid>

fails in load_env() because it calls .values() on jsons:

AttributeError: 'list' object has no attribute 'values'

and:

POST /compare/main+<eid>

fails in compare_envs() because it calls .keys():

AttributeError: 'list' object has no attribute 'keys'

If the values inside jsons are also malformed, the failure happens when the pane is accessed:

AttributeError: 'str' object has no attribute 'get'

Reproduction

  1. Start Visdom with an empty environment directory:
bash
python -m visdom.server -port 8097 -env_path /tmp/visdom-envs
  1. Create an invalid environment:
bash
echo '{"jsons": [], "reload": {}}' > /tmp/broken.json
  1. Upload it:
bash
curl -s -F "file=@/tmp/broken.json" http://localhost:8097/upload_env

The upload succeeds:

json
{
  "success": true,
  "eid": "uploaded_broken_3ea1ac89",
  "message": "Dashboard loaded successfully as 'uploaded_broken_3ea1ac89'"
}
  1. Open the environment from the UI.

The environment is listed, but opening it results in HTTP 500.

  1. Select the broken environment together with another environment and run compare.

This also results in HTTP 500.

  1. Restart the server.

The environment is loaded again from disk, and the same errors occur.

The same problem can also be reproduced by placing any of the following directly in <env_path>:

json
{"jsons": [], "reload": {}}
json
{"jsons": null, "reload": {}}
json
{"jsons": {"w1": "not a pane"}, "reload": {}}

Current validation

There are three places where the environment structure is checked, but all of them only check whether the keys exist.

In UploadEnvHandler.post():

python
if not (isinstance(data, dict) and "jsons" in data and "reload" in data):
    self.set_status(400)
    self.write({"success": False, "error": "This is not a valid Visdom JSON"})
    return

The data is then stored without checking the values:

python
self.state[new_eid] = {
    "jsons": data["jsons"],
    "reload": data["reload"]
}

JSONStore.load_env() performs the same two-key check when loading an environment from disk.

LazyEnvData.prime() also only rejects an environment when jsons or reload is missing. An environment containing both keys but with the wrong types passes this check and fails later when the data is used.

This means:

  • missing jsons → handled as invalid
  • missing reload → handled as invalid
  • jsons=[] → accepted
  • jsons=None → accepted
  • jsons={"w1": "not a pane"} → accepted
  • reload=[] → accepted

Expected behavior

Malformed environments should be rejected before they are added to server state.

For uploads, /upload_env should return the existing:

400 This is not a valid Visdom JSON

and should not write the invalid environment to disk or state.

For environment files already on disk, JSONStore.load_env() should skip invalid files in the same way it skips files that cannot be parsed.

If an invalid environment somehow reaches load_env() or compare_envs(), it should raise ValueError so the existing handlers can return the normal "invalid environment JSON format" notification instead of an uncaught 500.

Proposed fix

The environment shape can be checked in one place:

python
def env_is_well_formed(env):
    """Whether ``env`` has the shape expected by environment readers."""
    if not isinstance(env, Mapping):
        return False

    jsons = env.get("jsons")
    reload_data = env.get("reload")

    if not isinstance(jsons, Mapping):
        return False

    if not isinstance(reload_data, Mapping):
        return False

    return all(isinstance(pane, Mapping) for pane in jsons.values())

The same validation can then be used by:

  • UploadEnvHandler.post()
  • JSONStore.load_env()
  • load_env()
  • compare_envs()

Using Mapping instead of only dict also allows the check to work with mapping-like objects such as LazyEnvData.

An empty/missing environment is still represented by {} and should not be treated as a malformed environment.

Impact

The default Visdom server does not require authentication, so a client that can access the server can upload a malformed environment that is then visible to other connected users.

The environment can be removed manually, but the UI does not indicate that the environment is invalid. The failure is only visible in the server logs as a 500 traceback.

Testing

I have implemented the validation with unit tests covering:

  • malformed jsons values
  • malformed reload values
  • malformed pane values
  • invalid environments loaded from disk
  • invalid environments passed to the readers
  • valid environments that should continue to work

The tests cover nine malformed cases along with valid environment cases.

The change is implemented locally and is ready for a PR if this approach looks reasonable.