-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactor to avoid Proxy-Authorization leak
- Loading branch information
An Tran
committed
Sep 27, 2023
1 parent
d3b86b9
commit 5c0edbc
Showing
5 changed files
with
119 additions
and
32 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
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
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 |
---|---|---|
|
@@ -389,7 +389,7 @@ using proxy: http://foo:[email protected]:$TEST_NGINX_HTTP_PROXY_PORT | |
"name": "apicast.policy.apicast" | ||
}, | ||
{ | ||
"name": "apicast.policy.http_proxy", | ||
"name": "apicast.policy.camel", | ||
"configuration": { | ||
"all_proxy": "http://foo:[email protected]:$TEST_NGINX_HTTP_PROXY_PORT" | ||
} | ||
|
@@ -425,7 +425,6 @@ using proxy: http://foo:[email protected]:$TEST_NGINX_HTTP_PROXY_PORT | |
|
||
|
||
=== TEST 7: using HTTPS proxy for backend with Basic Auth. | ||
--- ONLY | ||
--- init eval | ||
$Test::Nginx::Util::PROXY_SSL_PORT = Test::APIcast::get_random_port(); | ||
$Test::Nginx::Util::ENDPOINT_SSL_PORT = Test::APIcast::get_random_port(); | ||
|
@@ -436,7 +435,7 @@ $Test::Nginx::Util::ENDPOINT_SSL_PORT = Test::APIcast::get_random_port(); | |
{ | ||
"backend_version": 1, | ||
"proxy": { | ||
"api_backend": "https://localhost:$Test::Nginx::Util::ENDPOINT_SSL_PORT", | ||
"api_backend": "https://127.0.0.1:$Test::Nginx::Util::ENDPOINT_SSL_PORT", | ||
"proxy_rules": [ | ||
{ "pattern": "/test", "http_method": "GET", "metric_system_name": "hits", "delta": 2 } | ||
], | ||
|
@@ -476,15 +475,8 @@ EOF | |
access_by_lua_block { | ||
assert = require('luassert') | ||
local proxy_auth = ngx.req.get_headers()['Proxy-Authorization'] | ||
assert.equals(proxy_auth, "Basic Zm9vOmJhcg==") | ||
|
||
assert.equal('https', ngx.var.scheme) | ||
assert.equal('$Test::Nginx::Util::ENDPOINT_SSL_PORT', ngx.var.server_port) | ||
assert.equal('localhost', ngx.var.ssl_server_name) | ||
assert.equal(ngx.var.request_uri, '/test?user_key=test3') | ||
assert.falsy(proxy_auth) | ||
|
||
local host = ngx.req.get_headers()["Host"] | ||
assert.equal(host, 'localhost:$Test::Nginx::Util::ENDPOINT_SSL_PORT') | ||
ngx.say("yay, endpoint backend") | ||
|
||
} | ||
|
@@ -507,9 +499,6 @@ server { | |
EOF | ||
--- request | ||
GET /test?user_key=test3 | ||
--- more_headers | ||
User-Agent: Test::APIcast::Blackbox | ||
ETag: foobar | ||
--- error_code: 200 | ||
--- user_files fixture=tls.pl eval | ||
--- error_log eval | ||
|
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
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 |
---|---|---|
|
@@ -1227,3 +1227,99 @@ proxy request: CONNECT test-upstream.lvh.me:$TEST_NGINX_RANDOM_PORT HTTP/1.1 | |
--- no_error_log | ||
[error] | ||
--- user_files fixture=tls.pl eval | ||
=== TEST 23: upstream API connection uses http proxy with BasicAuth | ||
--- env eval | ||
( | ||
"http_proxy" => "http://foo:bar\@127.0.0.1:$ENV{TEST_NGINX_HTTP_PROXY_PORT}", | ||
'BACKEND_ENDPOINT_OVERRIDE' => "http://test_backend.lvh.me:$ENV{TEST_NGINX_SERVER_PORT}" | ||
) | ||
--- configuration | ||
{ | ||
"services": [ | ||
{ | ||
"backend_version": 1, | ||
"proxy": { | ||
"api_backend": "http://test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT", | ||
"proxy_rules": [ | ||
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 } | ||
] | ||
} | ||
} | ||
] | ||
} | ||
--- backend | ||
server_name test_backend.lvh.me; | ||
location /transactions/authrep.xml { | ||
content_by_lua_block { | ||
ngx.exit(ngx.OK) | ||
} | ||
} | ||
--- upstream | ||
server_name test-upstream.lvh.me; | ||
location / { | ||
access_by_lua_block { | ||
local assert = require('luassert') | ||
local proxy_auth = ngx.req.get_headers()['Proxy-Authorization'] | ||
assert.equals(proxy_auth, "Basic Zm9vOmJhcg==") | ||
} | ||
} | ||
--- request | ||
GET /?user_key=value | ||
--- error_code: 200 | ||
--- error_log env | ||
using proxy: http://foo:[email protected]:$TEST_NGINX_HTTP_PROXY_PORT | ||
--- no_error_log | ||
[error] | ||
=== TEST 24: upstream API connection uses proxy for https with BasicAuth | ||
--- env eval | ||
( | ||
"https_proxy" => "http://foo:bar\@127.0.0.1:$ENV{TEST_NGINX_HTTP_PROXY_PORT}", | ||
'BACKEND_ENDPOINT_OVERRIDE' => "http://test_backend.lvh.me:$ENV{TEST_NGINX_SERVER_PORT}" | ||
) | ||
--- configuration random_port env | ||
{ | ||
"services": [ | ||
{ | ||
"backend_version": 1, | ||
"proxy": { | ||
"api_backend": "https://test-upstream.lvh.me:$TEST_NGINX_RANDOM_PORT", | ||
"proxy_rules": [ | ||
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 } | ||
] | ||
} | ||
} | ||
] | ||
} | ||
--- backend | ||
server_name test_backend.lvh.me; | ||
location /transactions/authrep.xml { | ||
content_by_lua_block { | ||
ngx.exit(ngx.OK) | ||
} | ||
} | ||
--- upstream env | ||
server_name test-upstream.lvh.me; | ||
listen $TEST_NGINX_RANDOM_PORT ssl; | ||
ssl_certificate $TEST_NGINX_SERVER_ROOT/html/server.crt; | ||
ssl_certificate_key $TEST_NGINX_SERVER_ROOT/html/server.key; | ||
location / { | ||
echo_foreach_split '\r\n' $echo_client_request_headers; | ||
echo $echo_it; | ||
echo_end; | ||
} | ||
--- request | ||
GET /test?user_key=test3 | ||
--- error_code: 200 | ||
--- error_log env | ||
using proxy: http://foo:[email protected]:$TEST_NGINX_HTTP_PROXY_PORT | ||
proxy request: CONNECT test-upstream.lvh.me:$TEST_NGINX_RANDOM_PORT HTTP/1.1 | ||
got header line: Proxy-Authorization: Basic Zm9vOmJhcg== | ||
--- no_error_log | ||
[error] | ||
--- user_files fixture=tls.pl eval |