{"record":{"id":"31a7fff8f19712b7","repo":"gitlabhq/gitlabhq","slug":"cannot-determine-hostname-from-url-for-bare-key","errorCode":null,"errorMessage":"cannot determine hostname from URL for bare key","messagePattern":"cannot determine hostname from URL for bare key","errorType":"exception","errorClass":"RemoteMirrors::HostKeysConverter::InvalidHostKeyError","httpStatus":400,"severity":"error","filePath":"app/models/remote_mirrors/host_keys_converter.rb","lineNumber":102,"sourceCode":"\n    def sanitize_key(key)\n      parts = Gitlab::SSHPublicKey.extract_key_parts(key)\n      return key unless parts\n\n      [parts[:prefix].presence, parts[:algorithm], restore_base64_encoding(parts[:key_data])].compact.join(' ')\n    end\n\n    # Form-encoded params (application/x-www-form-urlencoded) decode '+' as spaces.\n    # SSH key base64 data uses '+' characters, so we restore them here.\n    def restore_base64_encoding(key_data)\n      key_data.tr(' ', '+')\n    end\n\n    def normalize_key(key)\n      return if key.blank?\n      return key if key.match?(KEY_WITH_HOSTNAME_REGEX)\n\n      raise InvalidHostKeyError, [\"cannot determine hostname from URL for bare key\"] if known_hosts_hostname.blank?\n\n      \"#{known_hosts_hostname} #{key}\"\n    end\n\n    def known_hosts_hostname\n      return if url.blank?\n\n      uri = Addressable::URI.parse(url)\n      host = uri.host\n      return if host.blank?\n\n      port = uri.port\n      return host if port.nil? || port == STANDARD_SSH_PORT\n\n      \"[#{host}]:#{port}\"\n    rescue Addressable::URI::InvalidURIError\n      nil\n    end","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/gitlabhq/gitlabhq/blob/55ee20384a1f55cb0e362dee1d07149613b1b9bf/app/models/remote_mirrors/host_keys_converter.rb#L84-L120","documentation":"Error \"cannot determine hostname from URL for bare key\" thrown in gitlabhq/gitlabhq.","triggerScenarios":"Thrown at app/models/remote_mirrors/host_keys_converter.rb:102 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55ee20384a1f55cb0e362dee1d07149613b1b9bf","analyzedAt":"2026-08-21T14:22:27.782Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}