Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowIllegalStartLineCharacters() ignored: InvalidHttpRequest{message='Illegal character in HTTP start line', lineNumber=1} #68

Open
octo-kumo opened this issue Apr 6, 2024 · 3 comments
Labels

Comments

@octo-kumo
Copy link

RawHttp rawHttp = new RawHttp(RawHttpOptions.newBuilder()
                .allowIllegalStartLineCharacters()
                .allowContentLengthMismatch()
                .allowComments()
                .allowIllegalConnectAuthority()
                .build());

I am trying to send some naughty requests via rawhttp, and its complaining about illegal start line characters even though I explicitly allowed it.

It appears that allowIllegalStartLineCharacters is ignored by HttpMetadataParser

private String parseStartLine(InputStream inputStream,
BiFunction<String, Integer, RuntimeException> createError,
boolean skipLeadingNewLine) throws IOException {
StringBuilder metadataBuilder = new StringBuilder();
final boolean allowNewLineWithoutReturn = options.allowNewLineWithoutReturn();
int b;
while ((b = inputStream.read()) >= 0) {
if (b == '\r') {
// expect new-line
int next = inputStream.read();
if (next < 0 || next == '\n') {
if (skipLeadingNewLine) {
skipLeadingNewLine = false;
continue;
}
break;
} else {
inputStream.close();
throw createError.apply("Illegal character after return", 1);
}
} else if (b == '\n') {
if (skipLeadingNewLine) {
skipLeadingNewLine = false;
continue;
}
if (!allowNewLineWithoutReturn) {
inputStream.close();
throw createError.apply("Illegal new-line character without preceding return", 1);
}
// unexpected, but let's accept new-line without returns
break;
} else {
char c = (char) b;
if (c == ' ' || FieldValues.isAllowedInVCHARs(c)) {
metadataBuilder.append(c);
} else {
throw createError.apply("Illegal character in HTTP start line", 1);
}
}
skipLeadingNewLine = false;
}
return metadataBuilder.toString();
}

@renatoathaydes
Copy link
Owner

You're right, I will fix this asap.

@renatoathaydes
Copy link
Owner

@octo-kumo it currently allows illegal characters in the URI part of the start-line.

Can you give me examples of things you think should be allowed? We can't just allow anything, there needs to be clear rules for what's allowed despite being illegal according to the spec.

@octo-kumo
Copy link
Author

"/NN/NN/NN/etc/passwd",
"/static\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\etc\\passwd",

Hi, these two paths triggered the exception.
They are both sent as GET requests to a normal host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants