Top Description Fields Constructors Methods
org.glassfish.grizzly.http.util

public Class HttpRequestURIDecoder

extends Object
Class Inheritance
Static Imports
org.glassfish.grizzly.utils.Charsets.UTF8_CHARSET

Utility class that make sure an HTTP url defined inside a MessageBytes is normalized, converted and valid. It also makes sure there is no security hole. Mainly, this class can be used by doing:



HttpRequestURIDecoder.decode(decodedURI, urlDecoder, encoding, b2cConverter);


Author
Jeanfrancois Arcand

Field Summary

Modifier and TypeField and Description
protected static final boolean
private static final boolean
private static final Logger
private static final int
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if the uriCC represents a normalized URI, or false otherwise
checkNormalize
(final CharChunk
URI to be checked (should be chars)
uriCC
)

Check that the URI is normalized following character decoding.

protected void
convertMB(MessageBytes mb)

Character conversion of the a US-ASCII MessageBytes.

public static void
convertToChars(final DataChunk
- The bytes to decode
decodedURI
,
Charset
the encoding value, default is UTF-8.
encoding
)

Converts the normalized the HTTP request represented by the bytes inside DataChunk to chars representation, using the passed encoding.

private static void
convertURI(final MessageBytes
- The bytes to decode
uri
,
final String
the encoding value
encoding
,
B2CConverter
the Bytes to Char Converter.
b2cConverter
)

Convert a URI using the specified encoding, using the specified [@link B2CConverter} to decode the request.

protected static void
copyBytes(byte[] b, int dest, int src, int len)

Copy an array of bytes to a different position.

private static void
copyChars(char[] c, int dest, int src, int len)

Copy an array of chars to a different position.

public static void
decode(final MessageBytes
- The bytes to decode
decodedURI
,
final UDecoder
- The urlDecoder to use to decode.
urlDecoder
)

Decode the http request represented by the bytes inside MessageBytes using an UDecoder.

public static void
decode(final MessageBytes
- The bytes to decode
decodedURI
,
final UDecoder
- The urlDecoder to use to decode.
urlDecoder
,
String
the encoding value, default is UTF-8.
encoding
,
final B2CConverter
the Bytes to Char Converter.
b2cConverter
)

Decode the HTTP request represented by the bytes inside MessageBytes using an UDecoder, using the specified encoding, using the specified [@link B2CConverter} to decode the request.

public static void
decode(final DataChunk
- The bytes to decode
decodedURI
)

Decode the HTTP request represented by the bytes inside DataChunk.

public static void
decode(final DataChunk
- The bytes to decode
decodedURI
,
final boolean
allow encoded slashes
isSlashAllowed
)

Decode the HTTP request represented by the bytes inside DataChunk.

public static void
decode(final DataChunk
- The bytes to decode
decodedURI
,
final boolean
allow encoded slashes
isSlashAllowed
,
final Charset
the encoding value, default is UTF-8.
encoding
)

Decode the HTTP request represented by the bytes inside DataChunk.

public static void
decode(final DataChunk
- The bytes to decode
originalURI
,
final DataChunk
the target DataChunk URI will be decoded to
targetDecodedURI
,
final boolean
is '/' an allowable character
isSlashAllowed
,
final Charset
the encoding value, default is UTF-8
encoding
)

Decode the HTTP request represented by the bytes inside DataChunk.

protected void
log(String
Message to be logged
message
)

Log a message on the Logger associated with our Container (if any)

protected void
log(String
Message to be logged
message
,
Throwable
Associated exception
throwable
)

Log a message on the Logger associated with our Container (if any)

public static boolean

Returns:

true if normalization was successful, or false otherwise
normalize
(MessageBytes
URI to be normalized
uriMB
)

Normalize URI.

public static boolean

Returns:

true if normalization was successful, or false otherwise
normalize
(final DataChunk
URI to be normalized
dataChunk
)

Normalize URI.

public static boolean
public static boolean
public static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLOW_BACKSLASHback to summary
protected static final boolean ALLOW_BACKSLASH
COLLAPSE_ADJACENT_SLASHESback to summary
private static final boolean COLLAPSE_ADJACENT_SLASHES
LOGGERback to summary
private static final Logger LOGGER
STATE_CHARback to summary
private static final int STATE_CHAR
STATE_PERCENTback to summary
private static final int STATE_PERCENT
STATE_SLASHback to summary
private static final int STATE_SLASH
STATE_SLASHDOTback to summary
private static final int STATE_SLASHDOT
STATE_SLASHDOTDOTback to summary
private static final int STATE_SLASHDOTDOT

Constructor Detail

HttpRequestURIDecoderback to summary
public HttpRequestURIDecoder()

Method Detail

checkNormalizeback to summary
public static boolean checkNormalize(final CharChunk uriCC)

Check that the URI is normalized following character decoding.

This method checks for "\", 0, "//", "/./" and "/../". This method will return false if sequences that are supposed to be normalized are still present in the URI.

Parameters
uriCC:CharChunk

URI to be checked (should be chars)

Returns:boolean

true if the uriCC represents a normalized URI, or false otherwise

convertMBback to summary
protected void convertMB(MessageBytes mb)

Character conversion of the a US-ASCII MessageBytes.

convertToCharsback to summary
public static void convertToChars(final DataChunk decodedURI, Charset encoding) throws CharConversionException

Converts the normalized the HTTP request represented by the bytes inside DataChunk to chars representation, using the passed encoding.

Parameters
decodedURI:DataChunk

- The bytes to decode

encoding:Charset

the encoding value, default is UTF-8.

convertURIback to summary
private static void convertURI(final MessageBytes uri, final String encoding, B2CConverter b2cConverter) throws Exception

Convert a URI using the specified encoding, using the specified [@link B2CConverter} to decode the request.

Parameters
uri:MessageBytes

- The bytes to decode

encoding:String

the encoding value

b2cConverter:B2CConverter

the Bytes to Char Converter.

copyBytesback to summary
protected static void copyBytes(byte[] b, int dest, int src, int len)

Copy an array of bytes to a different position. Used during normalization.

copyCharsback to summary
private static void copyChars(char[] c, int dest, int src, int len)

Copy an array of chars to a different position. Used during normalization.

decodeback to summary
public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder) throws Exception

Decode the http request represented by the bytes inside MessageBytes using an UDecoder.

Parameters
decodedURI:MessageBytes

- The bytes to decode

urlDecoder:UDecoder

- The urlDecoder to use to decode.

decodeback to summary
public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder, String encoding, final B2CConverter b2cConverter) throws Exception

Decode the HTTP request represented by the bytes inside MessageBytes using an UDecoder, using the specified encoding, using the specified [@link B2CConverter} to decode the request.

Parameters
decodedURI:MessageBytes

- The bytes to decode

urlDecoder:UDecoder

- The urlDecoder to use to decode.

encoding:String

the encoding value, default is UTF-8.

b2cConverter:B2CConverter

the Bytes to Char Converter.

decodeback to summary
public static void decode(final DataChunk decodedURI) throws CharConversionException

Decode the HTTP request represented by the bytes inside DataChunk.

Parameters
decodedURI:DataChunk

- The bytes to decode

decodeback to summary
public static void decode(final DataChunk decodedURI, final boolean isSlashAllowed) throws CharConversionException

Decode the HTTP request represented by the bytes inside DataChunk.

Parameters
decodedURI:DataChunk

- The bytes to decode

isSlashAllowed:boolean

allow encoded slashes

decodeback to summary
public static void decode(final DataChunk decodedURI, final boolean isSlashAllowed, final Charset encoding) throws CharConversionException

Decode the HTTP request represented by the bytes inside DataChunk.

Parameters
decodedURI:DataChunk

- The bytes to decode

isSlashAllowed:boolean

allow encoded slashes

encoding:Charset

the encoding value, default is UTF-8.

decodeback to summary
public static void decode(final DataChunk originalURI, final DataChunk targetDecodedURI, final boolean isSlashAllowed, final Charset encoding) throws CharConversionException

Decode the HTTP request represented by the bytes inside DataChunk.

Parameters
originalURI:DataChunk

- The bytes to decode

targetDecodedURI:DataChunk

the target DataChunk URI will be decoded to

isSlashAllowed:boolean

is '/' an allowable character

encoding:Charset

the encoding value, default is UTF-8

logback to summary
protected void log(String message)

Log a message on the Logger associated with our Container (if any)

Parameters
message:String

Message to be logged

logback to summary
protected void log(String message, Throwable throwable)

Log a message on the Logger associated with our Container (if any)

Parameters
message:String

Message to be logged

throwable:Throwable

Associated exception

normalizeback to summary
public static boolean normalize(MessageBytes uriMB)

Normalize URI.

This method normalizes "\", "//", "/./" and "/../". This method will return false when trying to go above the root, or if the URI contains a null byte.

Parameters
uriMB:MessageBytes

URI to be normalized

Returns:boolean

true if normalization was successful, or false otherwise

normalizeback to summary
public static boolean normalize(final DataChunk dataChunk)

Normalize URI.

This method normalizes "\", "//", "/./" and "/../". This method will return false when trying to go above the root, or if the URI contains a null byte.

Parameters
dataChunk:DataChunk

URI to be normalized

Returns:boolean

true if normalization was successful, or false otherwise

normalizeBufferback to summary
public static boolean normalizeBuffer(final BufferChunk bc)
normalizeBytesback to summary
public static boolean normalizeBytes(final ByteChunk bc)
normalizeCharsback to summary
public static boolean normalizeChars(final CharChunk uriCC)