-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MYFACES-3405 includeViewParameters re-evaluates param/model values as…
… EL expressions [CVE-2011-4343]
- Loading branch information
Leonardo Uribe
committed
Nov 22, 2011
1 parent
7c1ddcf
commit caee86e
Showing
7 changed files
with
231 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
api/src/main/java/javax/faces/application/_NavigationUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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 javax.faces.application; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.faces.context.FacesContext; | ||
|
||
/** | ||
* | ||
* @author Leonardo Uribe | ||
* | ||
*/ | ||
class _NavigationUtils | ||
{ | ||
/** | ||
* Evaluate all EL expressions found as parameters and return a map that can be used for | ||
* redirect or render bookmark links | ||
* | ||
* @param parameters parameter map retrieved from NavigationCase.getParameters() | ||
* @return | ||
*/ | ||
public static Map<String, List<String> > getEvaluatedNavigationParameters(Map<String, List<String> > parameters) | ||
{ | ||
Map<String,List<String>> evaluatedParameters = null; | ||
if (parameters != null && parameters.size() > 0) | ||
{ | ||
evaluatedParameters = new HashMap<String, List<String>>(); | ||
for (Map.Entry<String, List<String>> pair : parameters.entrySet()) | ||
{ | ||
boolean containsEL = false; | ||
for (String value : pair.getValue()) | ||
{ | ||
if (_isExpression(value)) | ||
{ | ||
containsEL = true; | ||
break; | ||
} | ||
} | ||
if (containsEL) | ||
{ | ||
evaluatedParameters.put(pair.getKey(), _evaluateValueExpressions(pair.getValue())); | ||
} | ||
else | ||
{ | ||
evaluatedParameters.put(pair.getKey(), pair.getValue()); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
evaluatedParameters = parameters; | ||
} | ||
return evaluatedParameters; | ||
} | ||
|
||
/** | ||
* Checks the Strings in the List for EL expressions and evaluates them. | ||
* Note that the returned List will be a copy of the given List, because | ||
* otherwise it will have unwanted side-effects. | ||
* @param values | ||
* @return | ||
*/ | ||
private static List<String> _evaluateValueExpressions(List<String> values) | ||
{ | ||
// note that we have to create a new List here, because if we | ||
// change any value on the given List, it will be changed in the | ||
// NavigationCase too and the EL expression won't be evaluated again | ||
List<String> target = new ArrayList<String>(values.size()); | ||
FacesContext context = FacesContext.getCurrentInstance(); | ||
for (String value : values) | ||
{ | ||
if (_isExpression(value)) | ||
{ | ||
// evaluate the ValueExpression | ||
value = context.getApplication().evaluateExpressionGet(context, value, String.class); | ||
} | ||
target.add(value); | ||
} | ||
return target; | ||
} | ||
|
||
private static boolean _isExpression(String text) | ||
{ | ||
return text.indexOf("#{") != -1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
shared/src/main/java/org/apache/myfaces/shared/application/NavigationUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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.myfaces.shared.application; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.faces.context.FacesContext; | ||
|
||
/** | ||
* | ||
* @author Leonardo Uribe | ||
* | ||
*/ | ||
public class NavigationUtils | ||
{ | ||
/** | ||
* Evaluate all EL expressions found as parameters and return a map that can be used for | ||
* redirect or render bookmark links | ||
* | ||
* @param parameters parameter map retrieved from NavigationCase.getParameters() | ||
* @return | ||
*/ | ||
public static Map<String, List<String> > getEvaluatedNavigationParameters(Map<String, List<String> > parameters) | ||
{ | ||
Map<String,List<String>> evaluatedParameters = null; | ||
if (parameters != null && parameters.size() > 0) | ||
{ | ||
evaluatedParameters = new HashMap<String, List<String>>(); | ||
for (Map.Entry<String, List<String>> pair : parameters.entrySet()) | ||
{ | ||
boolean containsEL = false; | ||
for (String value : pair.getValue()) | ||
{ | ||
if (_isExpression(value)) | ||
{ | ||
containsEL = true; | ||
break; | ||
} | ||
} | ||
if (containsEL) | ||
{ | ||
evaluatedParameters.put(pair.getKey(), _evaluateValueExpressions(pair.getValue())); | ||
} | ||
else | ||
{ | ||
evaluatedParameters.put(pair.getKey(), pair.getValue()); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
evaluatedParameters = parameters; | ||
} | ||
return evaluatedParameters; | ||
} | ||
|
||
/** | ||
* Checks the Strings in the List for EL expressions and evaluates them. | ||
* Note that the returned List will be a copy of the given List, because | ||
* otherwise it will have unwanted side-effects. | ||
* @param values | ||
* @return | ||
*/ | ||
private static List<String> _evaluateValueExpressions(List<String> values) | ||
{ | ||
// note that we have to create a new List here, because if we | ||
// change any value on the given List, it will be changed in the | ||
// NavigationCase too and the EL expression won't be evaluated again | ||
List<String> target = new ArrayList<String>(values.size()); | ||
FacesContext context = FacesContext.getCurrentInstance(); | ||
for (String value : values) | ||
{ | ||
if (_isExpression(value)) | ||
{ | ||
// evaluate the ValueExpression | ||
value = context.getApplication().evaluateExpressionGet(context, value, String.class); | ||
} | ||
target.add(value); | ||
} | ||
return target; | ||
} | ||
|
||
private static boolean _isExpression(String text) | ||
{ | ||
return text.indexOf("#{") != -1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters