From d3f69bbb71600fc75c9f821444b72e875a49daf6 Mon Sep 17 00:00:00 2001 From: "benjamin.baker" Date: Fri, 4 Sep 2026 16:19:28 -0400 Subject: [PATCH] Trust the binary PE version over the typed agent version Uploading an agent build whose product version carried semver build metadata (1.5.0+abcdef) was rejected, because the typed version string was validated as a dotted-numeric value before the file was ever read. That string is only a hint from the operator, and the build metadata it carries is not a legal directory name for the version store. The authority is the dotted-numeric FILE version stamped in the binary PE resource, so validation now happens after the upload is parsed: when the typed value is missing or not dotted-numeric, fall back to the detected version, and reject only when neither yields a usable one. --- plugins/endpoints/api/agentupload.py | 21 ++++-- .../frontend/views/AgentKeySettings.vue | 22 ++++--- .../test_endpoints_agentupload.py | 65 +++++++++++++++++++ 3 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 tests/test_plugins/test_endpoints_agentupload.py diff --git a/plugins/endpoints/api/agentupload.py b/plugins/endpoints/api/agentupload.py index ae463ab5..bc1a9fce 100644 --- a/plugins/endpoints/api/agentupload.py +++ b/plugins/endpoints/api/agentupload.py @@ -69,11 +69,6 @@ def upload_agent_binary(binkey): ErrorCodes.VALIDATION_ERROR, 'binkey must be one of: agent, tray', http_code=400) - if not agentstore.is_valid_version(version): - return error_response( - ErrorCodes.VALIDATION_ERROR, - 'version must be a dotted-numeric string such as 1.6.3', - http_code=400) upload = request.files.get('file') if upload is None or not upload.filename: @@ -94,6 +89,22 @@ def upload_agent_binary(binkey): 'uploaded file is not a Windows executable', http_code=400) + # Gate the version at the PE, not at the raw input. Product versions carry + # semver build metadata (1.5.0+abcdef...) that is not a legal directory + # name, so the operator's typed string is only a hint. The dotted-numeric + # FILE version stamped in the binary's PE resource is the authority; fall + # back to it whenever the typed value is missing or not dotted-numeric, and + # only reject when neither yields a usable version. + if not agentstore.is_valid_version(version): + detected = agentstore.read_pe_file_version(data) + if agentstore.is_valid_version(detected): + version = detected + else: + return error_response( + ErrorCodes.VALIDATION_ERROR, + 'version must be a dotted-numeric string such as 1.6.3', + http_code=400) + result = agentstore.store_version(binkey, version, data, make_current=makecurrent) diff --git a/plugins/endpoints/frontend/views/AgentKeySettings.vue b/plugins/endpoints/frontend/views/AgentKeySettings.vue index a3b659f3..f0d78107 100644 --- a/plugins/endpoints/frontend/views/AgentKeySettings.vue +++ b/plugins/endpoints/frontend/views/AgentKeySettings.vue @@ -355,7 +355,7 @@