Skip to content

Commit

Permalink
improve uri validation, check also for // after decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari committed Feb 26, 2014
1 parent 557879c commit 7df99cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/groovy/org/grails/plugin/resource/URLUtils.groovy
Expand Up @@ -39,7 +39,7 @@ class URLUtils {

/**
* Normalizes and decodes uri once.
* Check if result contains \ , /../ or /./ after decoding and throws IllegalArgumentException in that case
* Check if result contains \ , /../ , /./ or // after decoding and throws IllegalArgumentException in that case
*
* @param uri
* @return
Expand All @@ -53,7 +53,7 @@ class URLUtils {
}

String decoded = URLDecoder.decode(normalized, "UTF-8")
if(decoded.contains('\\') || decoded.contains('/./') || decoded.contains('/../')) {
if(decoded.contains('\\') || decoded.contains('/./') || decoded.contains('/../') || decoded.contains('//')) {
throw new IllegalArgumentException("illegal uri ${uri}")
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/org/grails/plugin/resource/URLUtilsSpec.groovy
Expand Up @@ -27,7 +27,7 @@ class URLUtilsSpec extends Specification {
normalizeUri('/parentdir/a%20b%20c.xml') == '/parentdir/a b c.xml'
}

def 'fail if contains .. path travelsal after decoding'() {
def 'fail if contains .. path traversal after decoding'() {
when:
normalizeUri('/some/path/%2e%2e/some-dir/file.xml')
then:
Expand All @@ -41,7 +41,7 @@ class URLUtilsSpec extends Specification {
thrown IllegalArgumentException
}

def 'fail if contains . path travelsal after decoding'() {
def 'fail if contains . path traversal after decoding'() {
when:
normalizeUri('/some/path/%2e/some-dir/file.xml')
then:
Expand Down

0 comments on commit 7df99cc

Please sign in to comment.