-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #487 from vimeo/fixing-path-traversal-bugs
Allow prepopulated query parameters while disallowing path traversal and other hosts
- Loading branch information
Showing
4 changed files
with
244 additions
and
217 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
25 changes: 25 additions & 0 deletions
25
...ore/src/main/java/com/vimeo/networking2/internal/interceptor/HostValidationInterceptor.kt
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,25 @@ | ||
package com.vimeo.networking2.internal.interceptor | ||
|
||
import com.vimeo.networking2.config.VimeoApiConfiguration | ||
import okhttp3.HttpUrl | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import okio.IOException | ||
|
||
/** | ||
* An interceptor that ensures that only requests to the host specified in the [VimeoApiConfiguration] are made. This | ||
* prevents unexpected requests from being made to other hosts. | ||
* | ||
* @param vimeoApiConfiguration The configuration used to determine the expected host. | ||
*/ | ||
class HostValidationInterceptor(private val vimeoApiConfiguration: VimeoApiConfiguration) : Interceptor { | ||
private val httpUrl = HttpUrl.parse(vimeoApiConfiguration.baseUrl) | ||
|
||
override fun intercept(chain: Interceptor.Chain): Response = | ||
if (chain.request().url().host() != httpUrl?.host()) { | ||
throw IOException("Host must match specified base URL, was ${chain.request().url().host()}, " + | ||
"expected ${httpUrl?.host()}") | ||
} else { | ||
chain.proceed(chain.request()) | ||
} | ||
} |
Oops, something went wrong.