Skip to content

Java micro-library for sanitzing unicode control characters

License

Notifications You must be signed in to change notification settings

ncredinburgh/in-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maven Central

InControl

A micro-library that removes Unicode control characters from a string and replaces them with the equivalent Control Picture. The primary use case is envisaged to be preventing log injection attacks (in combination with other techniques). By default control codes associated with formatting (tab, new line and carriage return) are not converted. Only C0 unicode control codes are covered,

Requires Java 8 or above.

Usage

If using Maven, the following dependency can be added to your pom.xml:

    <dependency>
      <groupId>com.ncredinburgh</groupId>
      <artifactId>in-control</artifactId>
      <version>1.1</version>
    </dependency>

The controlCharactersToPictures method can then be imported statically thus:

import static com.ncredinburgh.incontrol.InControl.controlCharactersToPictures;

class SomeClass {
    public String someMethod(final String someInput) {
        return controlCharactersToPictures(someInput);
    }
}

API

The full API can be found in the Javadoc.

controlCharactersToPictures(String) -> String

For a given string that contains control codes, return a new string containing pictures in their place. Excludes formatting codes (tab, new line, carriage return)

controlCharactersToPictures(String, boolean) -> String

For a given string that contains control codes, return a new string containing pictures in their place. When second parameter is false, exclude formatting codes (tab, new line, carriage return) from replacement, when true, include them.

About

Java micro-library for sanitzing unicode control characters

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages