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

Introduced protections against HTTP header injection / smuggling attacks #790

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,6 +25,7 @@

package jodd.htmlstapler;

import io.github.pixee.security.Newlines;
import jodd.bean.BeanUtil;
import jodd.io.IOUtil;
import jodd.lagarto.TagVisitor;
Expand Down Expand Up @@ -202,11 +203,11 @@ protected boolean processActionPath(final HttpServletRequest servletRequest, fin
throw new IOException("bundle not found: " + bundleId);
}

servletResponse.setHeader("Content-Length", String.valueOf(file.length()));
servletResponse.setHeader("Last-Modified", TimeUtil.formatHttpDate(file.lastModified()));
servletResponse.setHeader("Content-Length", Newlines.stripAll(String.valueOf(file.length())));
servletResponse.setHeader("Last-Modified", Newlines.stripAll(TimeUtil.formatHttpDate(file.lastModified())));

if (cacheMaxAge > 0) {
servletResponse.setHeader("Cache-Control", "max-age=" + cacheMaxAge);
servletResponse.setHeader("Cache-Control", Newlines.stripAll("max-age=" + cacheMaxAge));
}

sendBundleFile(servletResponse, file);
Expand Down
3 changes: 2 additions & 1 deletion jodd-madvoc/src/main/java/jodd/madvoc/scope/HeaderScope.java
Expand Up @@ -25,6 +25,7 @@

package jodd.madvoc.scope;

import io.github.pixee.security.Newlines;
import jodd.madvoc.ActionRequest;
import jodd.madvoc.config.Targets;

Expand Down Expand Up @@ -81,7 +82,7 @@ public void outject(final ActionRequest actionRequest, final Targets targets) {
targets.forEachTargetAndOut(this, (target, out) -> {
final String value = (String) target.readValue(out);
if (value != null) {
servletResponse.setHeader(out.name(), value);
servletResponse.setHeader(out.name(), Newlines.stripAll(value));
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion jodd-servlet/src/main/java/jodd/servlet/DispatcherUtil.java
Expand Up @@ -25,6 +25,7 @@

package jodd.servlet;

import io.github.pixee.security.Newlines;
import jodd.util.StringPool;

import javax.servlet.RequestDispatcher;
Expand Down Expand Up @@ -170,7 +171,7 @@ public static void redirectPermanent(final HttpServletRequest request, final Htt
url = ServletUtil.getContextPath(request) + url;
}
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", url);
response.setHeader("Location", Newlines.stripAll(url));
}


Expand Down
5 changes: 3 additions & 2 deletions jodd-servlet/src/main/java/jodd/servlet/ServletUtil.java
Expand Up @@ -25,6 +25,7 @@

package jodd.servlet;

import io.github.pixee.security.Newlines;
import jodd.core.JoddCore;
import jodd.http.upload.FileUpload;
import jodd.io.FileNameUtil;
Expand Down Expand Up @@ -145,7 +146,7 @@ public static String resolveAuthBearerToken(final HttpServletRequest request) {
* Sends correct headers to require basic authentication for the given realm.
*/
public static void requireAuthentication(final HttpServletResponse resp, final String realm) throws IOException {
resp.setHeader(WWW_AUTHENTICATE, "Basic realm=\"" + realm + '\"');
resp.setHeader(WWW_AUTHENTICATE, Newlines.stripAll("Basic realm=\"" + realm + '\"'));
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}

Expand Down Expand Up @@ -200,7 +201,7 @@ public static void prepareResponse(final HttpServletResponse response, final Str
final String encodedFileName = URLCoder.encode(name);

response.setHeader(CONTENT_DISPOSITION,
"attachment;filename=\"" + name + "\";filename*=utf8''" + encodedFileName);
Newlines.stripAll("attachment;filename=\"" + name + "\";filename*=utf8''" + encodedFileName));
}
}

Expand Down