Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3135c7f8
Commit
3135c7f8
authored
Oct 09, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Escape strings in whitelabel error page (HTML)
parent
6a503d5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
ErrorMvcAutoConfiguration.java
...ork/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java
+3
-1
DefaultErrorViewIntegrationTests.java
...t/autoconfigure/web/DefaultErrorViewIntegrationTests.java
+20
-4
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java
View file @
3135c7f8
...
@@ -52,9 +52,11 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
...
@@ -52,9 +52,11 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.util.PropertyPlaceholderHelper
;
import
org.springframework.util.PropertyPlaceholderHelper
;
import
org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver
;
import
org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver
;
import
org.springframework.web.bind.ServletRequestUtils
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.view.BeanNameViewResolver
;
import
org.springframework.web.servlet.view.BeanNameViewResolver
;
import
org.springframework.web.util.HtmlUtils
;
/**
/**
* {@link EnableAutoConfiguration Auto-configuration} to render errors via a MVC error
* {@link EnableAutoConfiguration Auto-configuration} to render errors via a MVC error
...
@@ -173,7 +175,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
...
@@ -173,7 +175,7 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
Expression
expression
=
SpelView
.
this
.
parser
.
parseExpression
(
name
);
Expression
expression
=
SpelView
.
this
.
parser
.
parseExpression
(
name
);
try
{
try
{
Object
value
=
expression
.
getValue
(
SpelView
.
this
.
context
);
Object
value
=
expression
.
getValue
(
SpelView
.
this
.
context
);
return
(
value
==
null
?
null
:
value
.
toString
(
));
return
(
value
==
null
?
null
:
HtmlUtils
.
htmlEscape
(
value
.
toString
()
));
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
return
null
;
return
null
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java
View file @
3135c7f8
...
@@ -16,6 +16,10 @@
...
@@ -16,6 +16,10 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
...
@@ -41,10 +45,6 @@ import org.springframework.test.web.servlet.MvcResult;
...
@@ -41,10 +45,6 @@ import org.springframework.test.web.servlet.MvcResult;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.WebApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
/**
* @author Dave Syer
* @author Dave Syer
*/
*/
...
@@ -74,6 +74,22 @@ public class DefaultErrorViewIntegrationTests {
...
@@ -74,6 +74,22 @@ public class DefaultErrorViewIntegrationTests {
assertTrue
(
"Wrong content: "
+
content
,
content
.
contains
(
"999"
));
assertTrue
(
"Wrong content: "
+
content
,
content
.
contains
(
"999"
));
}
}
@Test
public
void
testErrorWithEscape
()
throws
Exception
{
MvcResult
response
=
this
.
mockMvc
.
perform
(
get
(
"/error"
).
requestAttr
(
"javax.servlet.error.exception"
,
new
RuntimeException
(
"<script>alert('Hello World')</script>"
)).
accept
(
MediaType
.
TEXT_HTML
)).
andExpect
(
status
().
isOk
())
.
andReturn
();
String
content
=
response
.
getResponse
().
getContentAsString
();
assertTrue
(
"Wrong content: "
+
content
,
content
.
contains
(
"<script>"
));
assertTrue
(
"Wrong content: "
+
content
,
content
.
contains
(
"Hello World"
));
assertTrue
(
"Wrong content: "
+
content
,
content
.
contains
(
"999"
));
}
@Target
(
ElementType
.
TYPE
)
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Documented
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment