From a6dfbf9442ad2c103eb72b8a487ec8f248dbabaf Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Mon, 10 Feb 2014 08:54:43 -0500 Subject: [PATCH] mod_http_cache: fixed validation of S3 URL --- src/mod/applications/mod_http_cache/aws.c | 2 +- src/mod/applications/mod_http_cache/test_aws/main.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_http_cache/aws.c b/src/mod/applications/mod_http_cache/aws.c index bea30144db..4d446d5857 100644 --- a/src/mod/applications/mod_http_cache/aws.c +++ b/src/mod/applications/mod_http_cache/aws.c @@ -44,7 +44,7 @@ int aws_s3_is_s3_url(const char *url) { /* AWS bucket naming rules are complex... this match only supports virtual hosting of buckets */ - return !zstr(url) && switch_regex_match(url, "^https?://\\w[\\w.]{1,61}\\w\\.s3([-\\w]+)?\\.amazonaws\\.com/.*$") == SWITCH_STATUS_SUCCESS; + return !zstr(url) && switch_regex_match(url, "^https?://\\w[-\\w.]{1,61}\\w\\.s3([-\\w]+)?\\.amazonaws\\.com/.*$") == SWITCH_STATUS_SUCCESS; } /** diff --git a/src/mod/applications/mod_http_cache/test_aws/main.c b/src/mod/applications/mod_http_cache/test_aws/main.c index f9ed1dcfbf..c29f1364ec 100644 --- a/src/mod/applications/mod_http_cache/test_aws/main.c +++ b/src/mod/applications/mod_http_cache/test_aws/main.c @@ -107,6 +107,10 @@ static void test_parse_url(void) aws_s3_parse_url(strdup("http://bucket.s3.amazonaws.com/voicemails/recording.wav"), &bucket, &object); ASSERT_STRING_EQUALS("bucket", bucket); ASSERT_STRING_EQUALS("voicemails/recording.wav", object); + + aws_s3_parse_url(strdup("https://my-bucket-with-dash.s3-us-west-2.amazonaws.com/greeting/file/1002/Lumino.mp3"), &bucket, &object); + ASSERT_STRING_EQUALS("my-bucket-with-dash", bucket); + ASSERT_STRING_EQUALS("greeting/file/1002/Lumino.mp3", object); } /**