fix: start pull events when the pull begins and reject unsafe image names

The pull started event was emitted by the route before the pull took
its per compute lock, so a request queued behind another pull claimed
to be running while it was still waiting. The pull now reports the
started state itself, once it owns the lock.

Deleting an image interpolates the name into the daemon API path. The
pattern on the path parameter limits it to the characters of an image
reference and validate_docker_image_name also rejects "..", so a name
cannot escape that path. Applied on both the controller and compute
routes.
This commit is contained in:
YueGuobin committed 2026-11-06 15:42:51 +08:00
1 parent d5d25eba06
commit 04a8ba06a8
7 files changed
+99 -18

No files matched your search

@@ -245,6 +245,21 @@ class TestComputeFeatures:
)
assert response.status_code == status.HTTP_204_NO_CONTENT
async def test_compute_delete_docker_image_rejects_path_traversal(
self, app: FastAPI, client: AsyncClient, test_compute: Compute
) -> None:
# percent encoded so the client does not normalize the ".." segments
# away before the request reaches the server
compute = MagicMock()
compute.http_query = AsyncioMagicMock(return_value={})
with patch("gns3server.api.routes.controller.computes.Controller.instance") as controller:
controller.return_value.get_compute.return_value = compute
response = await client.delete(
f"/v3/computes/{test_compute.compute_id}/docker/images/a%2F..%2F..%2Fversion"
)
compute.http_query.assert_not_called()
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
async def test_compute_load_docker_image(self, app: FastAPI, client: AsyncClient, test_compute: Compute) -> None:
compute = MagicMock()