Skip to content

Commit ab4c7a8

Browse files
authored
AAP-46641 Increase trusted header timeout (#831)
* trusted_header_timeout_in_ns --> trusted_header_timeout * Increase default validity period .3s --> 1s * Use milliseconds instead of nanoseconds
1 parent 099a1f4 commit ab4c7a8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

ansible_base/jwt_consumer/common/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ def validate_x_trusted_proxy_header(header_value: str, ignore_cache=False) -> bo
5353
logger.warning("Failed to validate x-trusted-proxy-header, malformed, expected value to contain a -")
5454
return False
5555

56-
# Validate that the header has been cut within the last 300ms (by default)
56+
# Validate that the header has been cut within the last 1000ms (by default)
5757
try:
58-
if time.time_ns() - int(timestamp) > get_setting('trusted_header_timeout_in_ns', 300000000):
59-
logger.warning(f"Timestamp {timestamp} was too old to be valid alter trusted_header_timeout_in_ns if needed")
58+
header_age_ms = round((time.time_ns() - int(timestamp)) / 1000000)
59+
if header_age_ms > get_setting('trusted_header_timeout', 1000):
60+
logger.warning(f"Timestamp {timestamp} was too old by {header_age_ms}ms to be valid-alter trusted_header_timeout if needed")
6061
return False
6162
except ValueError:
6263
logger.warning(f"Unable to convert timestamp (base64) {b64encode(timestamp.encode('UTF-8'))} into an integer")

test_app/tests/jwt_consumer/common/test_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def test_header_timeout(self, expected_log, rsa_keypair):
3737
# Assert this header is valid if used right away
3838
assert validate_x_trusted_proxy_header(header) is True
3939

40-
# By default the header is only valid for 300ms so a 1/2 second sleep will expire it
41-
time.sleep(0.5)
40+
# By default the header is only valid for 1000ms so a 1.1 second sleep will expire it
41+
time.sleep(1.1)
4242
with expected_log(
4343
'ansible_base.jwt_consumer.common.util.logger',
4444
'warning',
45-
'was too old to be valid alter trusted_header_timeout_in_ns if needed',
45+
'was too old by',
4646
):
4747
assert validate_x_trusted_proxy_header(header) is False
4848

0 commit comments

Comments
 (0)