{"record":{"id":"ad75c538c949b3a9","repo":"google/tsunami-security-scanner","slug":"name-cannot-be-none","errorCode":null,"errorMessage":"Name cannot be None.","messagePattern":"Name cannot be None\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"plugin_server/py/common/net/http/http_headers.py","lineNumber":45,"sourceCode":"    \"\"\"Get the first value for a specified HTTP field name.\"\"\"\n    values = self.get_all(name)\n    if not values:\n      return None\n    return values[0]\n\n  def get_all(self, name: str) -> list[str]:\n    \"\"\"Get all values for a specified HTTP field name.\n\n    Values are in the order they were added to the builder.\n\n    Args:\n      name: header name\n\n    Returns:\n      List of matched header values.\n    \"\"\"\n    if name is None:\n      raise ValueError('Name cannot be None.')\n    values = self.raw_headers.get(name, [])\n    if values:\n      return values\n    canonicalized_name = _canonicalize(name)\n    return self.raw_headers.get(canonicalized_name, [])\n\n  @classmethod\n  def builder(cls) -> 'Builder':\n    return Builder()\n\n\nclass Builder:\n  \"\"\"Builder class to create HTTP headers object.\n\n  Attributes:\n    http_headers: Collection of header field names and corresponding values.\n  \"\"\"\n  # RFC 2616 section 4.2.","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/google/tsunami-security-scanner/blob/363ba87b3543f8ae8e4304d3416818f03da7f262/plugin_server/py/common/net/http/http_headers.py#L27-L63","documentation":"HttpHeaders.get_all() raises ValueError('Name cannot be None.') when the requested header name is None. It performs an exact lookup then a canonicalized-name fallback, so a non-None (even unknown) name safely returns [].","triggerScenarios":"Calling http_headers.get(None) or get_all(None), typically when the header name comes from an unset variable, a failed regex group, or a config lookup returning None, at http_headers.py:45.","commonSituations":"Plugins reading headers from a mapping that returned None for a missing key; passing the result of a failed parse directly as the header name; iterating optional header names without defaults.","solutions":["Check the name is not None before calling get_all/get.","Provide a default header name at the call site (e.g. name or 'Content-Type').","Fix upstream parsing so a missing header yields a string, not None."],"exampleFix":"// before\nvalues = http_headers.get(header_name)\n// after\nif header_name is not None:\n    values = http_headers.get(header_name)\nelse:\n    values = []","handlingStrategy":"type-guard","validationCode":"assert header_name is not None, \"header name is required\"","typeGuard":"def safe_get(headers, name, default=None):\n    return headers.get_all(name) if name is not None else default","tryCatchPattern":"try:\n    values = http_headers.get(name)\nexcept ValueError:\n    values = []","preventionTips":["Never pass variables that can be None as header names.","Default missing header names with `or ''`/sentinel before lookup.","Check parsing code that produces header names for None results."],"tags":["python","http","headers","null-check"],"backgroundTag":"null-argument","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"}