-
Notifications
You must be signed in to change notification settings - Fork 11
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
Handle bad signature on flash cookie like a missing signature #275
Comments
@cies I agree, we should remove |
Say no more @asolntsev , I'll produce a PR for this. :) |
While implementing this I stumbled on this: @Nonnull
public Scope.Flash restore(@Nonnull Http.Request request) {
Http.Cookie cookie = request.cookies.get(COOKIE_PREFIX + "_FLASH");
if (cookie == null) {
return new Scope.Flash();
}
int splitterPosition = cookie.value.indexOf('-');
if (splitterPosition == -1) {
logger.warn("Cookie without signature: {}", cookie.value);
return new Scope.Flash();
}
String signature = cookie.value.substring(0, splitterPosition);
String realValue = cookie.value.substring(splitterPosition + 1);
if (!signer.isValid(signature, realValue)) {
throw new Forbidden(String.format("Invalid flash signature: %s", cookie.value));
}
return new Scope.Flash(encoder.decode(realValue));
} Basically if you remove the signature: it passes with a warning in the logs, but you get an empty flash object back. While if you have the signature wrong you get a now 500 error (and according to the to-be-produced PR a Forbidden error). This is unjust to the point that I think it's better to let both log a message as warning AND let both return an empty flash object, fair and square. We get about 10 I have made a PR that handles bad signatures, as it handles missing signatures. |
ForbiddenException
should be Forbidden
@cies I would say that it's better to throw an exception in both cases. It's safer. I think we left just a log only because of backward compatibility.
So it was just a transition period. |
Ok, will change that. Did not know the history. |
Fixed it. Both cases. |
Why do we need two? Currently the
ForbiddenException
is thrown when the flash signature is incorrect. This is clearly not a 5xx error, butForbiddenException
is handled like a 5xx error (errors in the logs and a 500 response).I think this is a
Forbidden
or aBadRequest
.Also I do not understand why we'd need both a
ForbiddenException
and aForbidden
exception. If there is a good reason this could be put in a code comment for future reference.The text was updated successfully, but these errors were encountered: