Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 832AB4AB4 for ; Mon, 23 May 2011 14:47:10 +0000 (UTC) Received: (qmail 18571 invoked by uid 500); 23 May 2011 14:47:10 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 18519 invoked by uid 500); 23 May 2011 14:47:10 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 18512 invoked by uid 99); 23 May 2011 14:47:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2011 14:47:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2011 14:47:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 183582388A32; Mon, 23 May 2011 14:46:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1126521 - in /sling/trunk: bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/issues/SLING2082Test.java Date: Mon, 23 May 2011 14:46:46 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110523144646.183582388A32@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Mon May 23 14:46:45 2011 New Revision: 1126521 URL: http://svn.apache.org/viewvc?rev=1126521&view=rev Log: SLING-2082 - escape HTML output in POST response, with test Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/issues/SLING2082Test.java (with props) Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java?rev=1126521&r1=1126520&r2=1126521&view=diff ============================================================================== --- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java (original) +++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/HtmlResponse.java Mon May 23 14:46:45 2011 @@ -140,7 +140,7 @@ public class HtmlResponse extends Abstra state = 0; Object prop = getProperty(varBuffer.toString()); if (prop != null) { - out.write(prop.toString()); + out.write(htmlEscape(prop.toString())); } varBuffer.setLength(0); } else { @@ -152,4 +152,24 @@ public class HtmlResponse extends Abstra out.flush(); } + /** HTML escaping */ + static String htmlEscape(String str) { + if(str == null) { + return null; + } + final StringBuilder out = new StringBuilder(); + for(int i=0; i < str.length(); i++) { + final char c = str.charAt(i); + if(c == '<') { + out.append("<"); + } else if (c == '>') { + out.append(">"); + } else if(c == '&') { + out.append("&"); + } else { + out.append(c); + } + } + return out.toString(); + } } \ No newline at end of file Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/issues/SLING2082Test.java URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/issues/SLING2082Test.java?rev=1126521&view=auto ============================================================================== --- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/issues/SLING2082Test.java (added) +++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/issues/SLING2082Test.java Mon May 23 14:46:45 2011 @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.launchpad.webapp.integrationtest.issues; + +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.sling.commons.testing.integration.HttpTestBase; + +public class SLING2082Test extends HttpTestBase { + + public void testPOST() throws Exception { + final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + Math.random() + ".html/%22%3e%3cscript%3ealert(29679)%3c/script%3e"; + final PostMethod post = new PostMethod(url); + post.setFollowRedirects(false); + final int status = httpClient.executeMethod(post); + assertEquals(201, status); + final String content = getResponseBodyAsStream(post, 0); + final String scriptTag = "