{"record":{"id":"2d529e19ad0d9b24","repo":"grpc/grpc-java","slug":"invalid-authority","errorCode":null,"errorMessage":"Invalid authority: ","messagePattern":"Invalid authority: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/grpc/internal/GrpcUtil.java","lineNumber":523,"sourceCode":"  }\n\n  /**\n   * Returns the build version of gRPC.\n   */\n  public static GrpcBuildVersion getGrpcBuildVersion() {\n    return new GrpcBuildVersion(\"gRPC Java\", IMPLEMENTATION_VERSION);\n  }\n\n  /**\n   * Parse an authority into a URI for retrieving the host and port.\n   */\n  public static URI authorityToUri(String authority) {\n    Preconditions.checkNotNull(authority, \"authority\");\n    URI uri;\n    try {\n      uri = new URI(null, authority, null, null, null);\n    } catch (URISyntaxException ex) {\n      throw new IllegalArgumentException(\"Invalid authority: \" + authority, ex);\n    }\n    return uri;\n  }\n\n  /**\n   * Verify {@code authority} is valid for use with gRPC. The syntax must be valid and it must not\n   * include userinfo.\n   *\n   * @return the {@code authority} provided\n   */\n  public static String checkAuthority(String authority) {\n    URI uri = authorityToUri(authority);\n    // Verify that the user Info is not provided.\n    checkArgument(uri.getAuthority().indexOf('@') == -1,\n        \"Userinfo must not be present on authority: '%s'\", authority);\n    return authority;\n  }\n","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/core/src/main/java/io/grpc/internal/GrpcUtil.java#L505-L541","documentation":"GrpcUtil.authorityToUri converts a channel authority string into a URI with only a scheme-less authority component. URIs built from an authority are strict; if the authority is null-checked OK but syntactically invalid (illegal characters, bad IPv6 literal, etc.), the URISyntaxException is rethrown as IllegalArgumentException(\"Invalid authority: ...\").","triggerScenarios":"Calling withTargetAuthority / building a channel with an authority string that java.net.URI rejects, e.g. containing spaces, underscores, an unbracketed IPv6 address, or other illegal characters.","commonSituations":"Passing raw host:port with special characters as the authority; constructing authority from user input without validation; IPv6 targets written without [ ] brackets.","solutions":["Fix the authority string: URL-escape or remove illegal characters, and bracket IPv6 literals like [::1]:50051.","Build the authority with GrpcUtil.authorityFromHostAndPort(host, port) instead of manual string concatenation.","Validate the authority with `new URI(null, authority, null, null, null)` in a try/catch before passing it to the channel builder."],"exampleFix":"// before\nString authority = \"my_host_underscore:50051\"; // rejected by URI\n// after\nString authority = GrpcUtil.authorityFromHostAndPort(\"myhost\", 50051);","handlingStrategy":"validation","validationCode":"try {\n  new URI(null, authority, null, null, null);\n} catch (URISyntaxException e) {\n  throw new IllegalArgumentException(\"Illegal authority: \" + authority, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  uri = GrpcUtil.authorityToUri(authority);\n} catch (IllegalArgumentException e) {\n  // sanitize/rebuild the authority\n}","preventionTips":["Build authorities with authorityFromHostAndPort, not string concatenation.","Bracket IPv6 literals and strip whitespace/special characters.","Sanitize user-supplied endpoints before passing them to channel builders."],"tags":["grpc","uri","authority","argument-validation"],"backgroundTag":"invalid-url-format","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}