{"record":{"id":"dfd7680822a5693f","repo":"google/tsunami-security-scanner","slug":"invalid-network-service-s","errorCode":null,"errorMessage":"Invalid network service: %s","messagePattern":"Invalid network service: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"plugin_server/py/common/data/network_service_utils.py","lineNumber":110,"sourceCode":"      service_context=ServiceContext(\n          web_service_context=WebServiceContext(application_root=uri.path)\n      )\n  )\n\n\ndef build_web_application_root_url(network_service: NetworkService) -> str:\n  \"\"\"Build the root url for web application service.\n\n  Args:\n    network_service: network service protobuf with a valid service defined\n    in the is_plain_http_by_known_web_service_name dict.\n\n  Returns:\n    The root URL for the web service which always ends with a \"/\"\n    (i.e., http://localhost:8080/, https://127.1.23.1/pathway/)\n  \"\"\"\n  if not is_web_service(network_service):\n    raise ValueError(\"Invalid network service: %s\" % network_service)\n  return build_web_protocol(\n      network_service) + build_web_uri_authority(\n          network_service) + build_web_app_root_path(network_service)\n\n\ndef build_web_protocol(network_service: NetworkService) -> str:\n  if is_plain_http_service(network_service):\n    return \"http://\"\n  else:\n    return \"https://\"\n\n\ndef build_web_uri_authority(network_service: NetworkService) -> str:\n  \"\"\"Creates URI authority using the network service.\n\n  The URI authority has 2 components: domain name and port number. Removes the\n  port number from URI authority if the web service uses the standard default\n  port. Port 80 for http/unsecure network and port 443 for https/secure","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/google/tsunami-security-scanner/blob/363ba87b3543f8ae8e4304d3416818f03da7f262/plugin_server/py/common/data/network_service_utils.py#L92-L128","documentation":"network_service_utils.build_web_application_root_url() raises ValueError when the given NetworkService is not a web service (i.e. is_web_service() returns False, meaning its service name is not http/https and its port is not a web port). The function can only build a root URL for recognized web protocols.","triggerScenarios":"Calling build_web_application_root_url with a NetworkService whose network_service is e.g. 'ssh' or 'mysql', or an unrecognized service, at network_service_utils.py:110.","commonSituations":"Plugin code iterating all discovered network services without filtering; port-scan results classifying a service by banner into a non-web name; assuming any open port is HTTP.","solutions":["Guard with is_web_service(network_service) before calling build_web_application_root_url.","Fix service discovery/classification so the service is correctly identified as http/https.","Skip non-web services in the plugin loop instead of building web URLs for them."],"exampleFix":"// before\nurl = network_service_utils.build_web_application_root_url(service)\n// after\nif network_service_utils.is_web_service(service):\n    url = network_service_utils.build_web_application_root_url(service)","handlingStrategy":"type-guard","validationCode":"assert network_service_utils.is_web_service(service), f\"not a web service: {service.network_service}\"","typeGuard":"def is_safe_web_service(service) -> bool:\n    return network_service_utils.is_web_service(service)","tryCatchPattern":"try:\n    url = network_service_utils.build_web_application_root_url(service)\nexcept ValueError as e:\n    logging.warning(\"Skipping non-web service: %s\", e)\n    url = None","preventionTips":["Always filter services with is_web_service before building web URLs.","Check service classification output after port scans.","Handle ValueError in plugin loops over heterogeneous services."],"tags":["python","network-service","validation","tsunami-plugin"],"backgroundTag":"invalid-argument-value","analyzedSha":"363ba87b3543f8ae8e4304d3416818f03da7f262","analyzedAt":"2026-09-13T01:50:53.990Z","contentChangedAt":"2026-09-13T01:50:53.990Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}