[Cycode] Fix for SAST detections - Observable Timing Discrepancy - #11
Open
cycode-security[bot] wants to merge 1 commit into
Open
[Cycode] Fix for SAST detections - Observable Timing Discrepancy#11cycode-security[bot] wants to merge 1 commit into
cycode-security[bot] wants to merge 1 commit into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Cycode] Fix for SAST detections - Observable Timing Discrepancy
Code fix
src / main / java / org / owasp / webgoat / lessons / passwordreset / ResetLinkAssignment.java
Code explainer
The vulnerability in this code is an Observable Timing Discrepancy, which occurs when the time taken to perform operations varies based on sensitive information. In this case, the issue is in the checkIfLinkIsFromTom method at line 73, where a direct string comparison (resetLink.equals(resetLinkFromForm)) is used to compare reset links. This comparison can terminate early if characters don't match, potentially allowing attackers to infer information about the reset link by measuring the time taken for the comparison. This is particularly dangerous because reset links are sensitive and could be used to gain unauthorized access.
The fix involves replacing the direct string comparison with a constant-time comparison using MessageDigest.isEqual. This method ensures that the comparison takes the same amount of time regardless of the input, preventing attackers from inferring information based on timing discrepancies. This approach aligns with security best practices for handling sensitive information, as recommended by OWASP and other security guidelines.
Remediation Instructions
To fix this vulnerability, follow these steps:
Identify the vulnerable comparison: Locate the checkIfLinkIsFromTom method where the direct string comparison is performed.
Replace the vulnerable comparison: Use a constant-time comparison method to ensure that the time taken for the comparison does not vary based on the input. Java provides MessageDigest.isEqual for this purpose, which performs a constant-time comparison.
Update the method: Modify the checkIfLinkIsFromTom method to use MessageDigest.isEqual for comparing the reset links.
Test the changes: Ensure that the functionality remains the same and that the comparison is now performed in constant time.