Class InertText

java.lang.Object
co.ankatech.ankasecure.sdk.util.InertText

public final class InertText extends Object
Renders a string that came from a server so that it can be put in an exception message, a log line or a terminal without acting on any of them.

Every message this SDK builds can be printed by a CLI or appended to a log, and some of its text is the server's: an RFC 9457 detail, an OAuth error_description, a streaming verdict's reason, OkHttp's "Unexpected status line: ..." carrying the first line a peer sent. On a path an attacker can write to, that text could carry an ANSI sequence, a CRLF opening a second line that reads like advice, or a bidirectional override that reverses what the reader sees.

The rule is shared with every ANKASecure client and pinned by one corpus:

  • every code point that acts on a terminal - Character.isISOControl(char) (C0 including TAB, DEL, C1 including U+009B), the format characters (bidi controls, zero-width characters, U+FEFF, the soft hyphen, the tag characters) and the line and paragraph separators - is written as a visible escape (a backslash, u and four uppercase hex digits), a supplementary one as its two UTF-16 escapes;
  • a lone surrogate becomes U+FFFD;
  • percent-encoding is not decoded;
  • the rendering holds at most 512 code points, an escape is never split, and a cut is marked with "...[truncated]".

A URI is rendered only from its parsed parts (uri(java.lang.String)). A redirect Location is never rendered at all: no caller passes one here.

This removes what ACTS, not what reveals: it is not redaction. The untouched bytes stay available to a caller that wants them, on AnkaSecureSdkException.getResponseBody() and down the cause chain.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The most code points a rendering holds, the truncation marker excluded.
    static final String
    Appended when the rendering was cut.
    static final String
    The rendering of a URI that does not parse, has no scheme or no host, or has a port that is not ASCII digits.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    text(String text)
    Renders server-supplied text terminal-safe.
    static String
    uri(String uri)
    Renders a server-supplied URI from its parsed parts only: scheme://host[:port][path], the host in its ASCII (punycode) form, never the userinfo, the query or the fragment.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_CODE_POINTS

      public static final int MAX_CODE_POINTS
      The most code points a rendering holds, the truncation marker excluded.
      See Also:
    • TRUNCATED

      public static final String TRUNCATED
      Appended when the rendering was cut.
      See Also:
    • UNPARSEABLE

      public static final String UNPARSEABLE
      The rendering of a URI that does not parse, has no scheme or no host, or has a port that is not ASCII digits.
      See Also:
  • Method Details

    • text

      public static String text(String text)
      Renders server-supplied text terminal-safe.
      Parameters:
      text - the untrusted text, which may be null
      Returns:
      the rendering, empty when text is null
    • uri

      public static String uri(String uri)
      Renders a server-supplied URI from its parsed parts only: scheme://host[:port][path], the host in its ASCII (punycode) form, never the userinfo, the query or the fragment. Every code point of the path outside printable ASCII (U+0020 to U+007E) is written as the same visible escape text(java.lang.String) uses, a supplementary one as its two UTF-16 escapes, and a lone surrogate becomes U+FFFD; percent-encoding is neither applied nor decoded. The result then follows text(java.lang.String).
      Parameters:
      uri - the untrusted URI, which may be null
      Returns:
      the rendering, or "<unparseable>" when it does not parse, has no scheme or host, or has a port that is not ASCII digits