Skip to content

Commit 5a25f63

Browse files
committedOct 11, 2014
use different strategy for extra check before serving urls
1 parent 92c51cd commit 5a25f63

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed
 

Diff for: ‎src/groovy/org/grails/plugin/resource/ResourceProcessor.groovy

+15-16
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class ResourceProcessor implements InitializingBean, ServletContextAware {
8787

8888
ServletContext servletContext
8989

90-
String rootUrlNormalized
91-
9290
boolean processingEnabled
9391

9492
List adHocIncludes
@@ -97,7 +95,6 @@ class ResourceProcessor implements InitializingBean, ServletContextAware {
9795
List optionalDispositions
9896

9997
boolean resourceLocatorEnabled
100-
boolean serveUnderRootPathOnly
10198

10299
ConcurrentMap<String, Boolean> servingAllowedCache
103100
ConcurrentMap<String, Boolean> resourceAllowedCache
@@ -140,10 +137,7 @@ class ResourceProcessor implements InitializingBean, ServletContextAware {
140137

141138
optionalDispositions = getConfigParamOrDefault('optional.dispositions', ['inline', 'image'])
142139

143-
rootUrlNormalized = urlToNormalizedFormat(resolveUriToURL('/'))
144-
145140
resourceLocatorEnabled = getConfigParamOrDefault('resourceLocatorEnabled', developmentMode)
146-
serveUnderRootPathOnly = getConfigParamOrDefault('serveUnderRootPathOnly', (resourceLocatorEnabled==false))
147141
}
148142

149143
/**
@@ -275,20 +269,25 @@ class ResourceProcessor implements InitializingBean, ServletContextAware {
275269
}
276270

277271
boolean doIsServingURLAllowed(String uri, URL url) {
278-
if(serveUnderRootPathOnly) {
279-
String urlAsString = urlToNormalizedFormat(url)
280-
if(urlAsString==null || rootUrlNormalized == null || !urlAsString.startsWith(rootUrlNormalized)) {
281-
return false
282-
}
283-
String relativePath = urlAsString.substring(rootUrlNormalized.length()-1)
284-
return canProcessLegacyResource(relativePath)
285-
} else {
286-
return canProcessLegacyResource(uri)
272+
String urlAsString = null
273+
try {
274+
urlAsString = urlToNormalizedFormat(url)
275+
} catch (Exception e) {
276+
log.warn("uri $uri is invalid. as url $url", e)
277+
}
278+
279+
if(urlAsString==null) {
280+
return false
281+
}
282+
// only allow urls that end with the uri given as input
283+
if(!urlAsString.endsWith(uri)) {
284+
return false
287285
}
286+
return canProcessLegacyResource(uri)
288287
}
289288

290289
static String urlToNormalizedFormat(URL url) {
291-
url != null ? url.toURI().normalize().toASCIIString() : null
290+
url != null ? url.toURI().normalize() : null
292291
}
293292

294293
/**

Diff for: ‎test/unit/org/grails/plugin/resource/ResourceProcessorSpec.groovy

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class ResourceProcessorSpec extends Specification {
2929
]
3030
resourceProcessor.servletContext = servletContext
3131
resourceProcessor.afterPropertiesSet()
32-
resourceProcessor.rootUrlNormalized = '/'
3332
request = new MockHttpServletRequest(servletContext)
3433
request.contextPath = '/'
3534
response = new MockHttpServletResponse()

0 commit comments

Comments
 (0)