Skip to content

HTTP Clock Skew Invalid Age header crash fix#2885

Closed
Tristanhx wants to merge 1 commit intotestssl:3.3devfrom
Tristanhx:http_clock_skew_fix
Closed

HTTP Clock Skew Invalid Age header crash fix#2885
Tristanhx wants to merge 1 commit intotestssl:3.3devfrom
Tristanhx:http_clock_skew_fix

Conversation

@Tristanhx
Copy link
Copy Markdown

Describe your changes

HTTP_clock_skew breaks execution of rest of script if Age header contains non-numerical values. This commit adds a check via regex for this value and removes the variable if it is invalid as if it was not given.

The run_http_date() function tries to run

difftime=$((HTTP_TIME + HTTP_AGE - NOW_TIME))

When the Age header is missing bash will automatically substitute with 0, but we found it sometimes occurs that the age header contains an entire date like the Date header. This will lead to an invalid expression and the script will halt.

The fix is checking if the Age header (if it exists) is purely numerical. If it is not a new heading and message is added to the output (but not the file output) and the HTTP_AGE variable is unset. This prevents the error that halts the script and allows the script to continue as if the Age header was not given.

What is your pull request about?

  • Bug fix
  • Improvement
  • New feature (adds functionality)
  • Breaking change (bug fix, feature or improvement that would cause existing functionality to not work as expected)
  • Typo fix
  • Documentation update
  • Update of other files

If it's a code change please check the boxes which are applicable

  • For the main program: My edits contain no tabs, indentation is five spaces and any line endings do not contain any blank chars
  • I've read CONTRIBUTING.md and Coding_Convention.md
  • I have tested this fix or improvement against >=2 hosts and I couldn't spot a problem
  • I have tested this new feature against >=2 hosts which show this feature and >=2 host which does not (in order to avoid side effects) . I couldn't spot a problem
  • For the new feature I have made corresponding changes to the documentation and / or to help()
  • If it's a bigger change: I added myself to CREDITS.md (alphabetical order) and the change to CHANGELOG.md

…ains non-numerical values. This commit adds a check via regex for this value and removes the variable if it is invalid as if it was not given.
@drwetter
Copy link
Copy Markdown
Collaborator

Good catch

Comment thread testssl.sh
if [[ -n "$HTTP_AGE" && ! "$HTTP_AGE" =~ ^[0-9]+$ ]]; then
pr_bold " HTTP Age Header "
out "Age header has invalid value: $HTTP_AGE (treated as 0)";
unset HTTP_AGE
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsetting HTTP_AGE is not equaly setting it to zero.

@drwetter
Copy link
Copy Markdown
Collaborator

Not sure whether I like this fix. Probably it's better to set it to NaN (here or in run_http_header()) and make sure the following statements can deal with that (see difftime).

You rather want me to fix that?

@drwetter drwetter closed this Sep 15, 2025
drwetter added a commit that referenced this pull request Sep 15, 2025
As suggested in #2885 parsing
of the server determined HTTP age var wasn't strict enough.

https://www.rfc-editor.org/rfc/rfc7234#section-1.2.1 requires the
variable to be a non-negative integer but testssl.sh assumed it was
like that but did't check whether that really was the case. This was
labled as a (potential) security problem. Potential as it didn't
look exploitable after review -- the header as a whole was already
sanitized.

This PR fixes the typs confusion and the garbled screen by checking
the variable early in run_http_header() and reset it to NaN. That
will be used later in run_http_date() to raise a low severity finding.

Kudos to @Tristanhx for catching this and for the suggested PR.

Also, only when running in debug mode, this PR fixes that during
service_detection() parts of the not-yet-sanitized header ended
up on the screen. The fix just calls sanitze_http_header() for the
temporary variable $TMPFILE.
@drwetter
Copy link
Copy Markdown
Collaborator

drwetter commented Sep 15, 2025

Thanks @Tristanhx , for the finding and the PR is much appreciated! 👍
👍
In the meantime I suggested a different fix though.

drwetter added a commit that referenced this pull request Sep 15, 2025
As suggested in #2885 parsing of the server determined HTTP age var wasn't strict enough, this is a backport for 3.2.

https://www.rfc-editor.org/rfc/rfc7234#section-1.2.1 requires the variable to be a non-negative integer but testssl.sh assumed it was like that but did't check whether that really was the case. This was labled as a (potential) security problem. Potential as it didn't look exploitable after review -- the header as a whole was already sanitized.

This PR fixes the typs confusion and the garbled screen by checking the variable early in run_http_header() and reset it to NaN. That will be used later in run_http_date() to raise a low severity finding.  Kudos to @Tristanhx for catching this and for the suggested PR.

Also, only when running in debug mode, this PR fixes that during service_detection() parts of the not-yet-sanitized header ended up on the screen. The fix just calls sanitze_http_header() for the temporary variable $TMPFILE.

For 3.2 sanitze_http_header() had to be modified to accept an argument and the callers needed to be changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants