Fix #236: Prevent fabricated epoch timestamps before NTP synchronization#237
Open
Psykii22 wants to merge 1 commit intoarduino-libraries:masterfrom
Open
Fix #236: Prevent fabricated epoch timestamps before NTP synchronization#237Psykii22 wants to merge 1 commit intoarduino-libraries:masterfrom
Psykii22 wants to merge 1 commit intoarduino-libraries:masterfrom
Conversation
… NTP synchronization
This commit implements a two-layer security fix to address the vulnerability
where getEpochTime() returned fabricated values (device uptime) before NTP
synchronization completed.
Security Issue:
- Before fix: getEpochTime() returned millis()/1000 (uptime values like 14, 16, 17...)
- These fabricated values could be mistaken for valid epoch timestamps
- Created authentication bypass vulnerabilities in security-sensitive applications
- Systems using timestamps for auth, replay protection, or HMAC were at risk
Layer 1 - Core Fix (getEpochTime):
- Now returns 0 when _lastUpdate == 0 (before synchronization)
- Aligns with ESP32 native SNTP behavior (time(nullptr) returns 0 until sync)
- Prevents fabricated values from being generated
- Fail-safe protection even if developers forget to check sync status
Layer 2 - Enhanced Validation (isTimeValid):
- New method that checks BOTH synchronization AND epoch reasonableness
- Returns true only if time is set AND epoch > 946684800 (Jan 1, 2000)
- Recommended for security-sensitive applications
- Catches edge cases where time might be "set" but invalid
Backward Compatibility:
- Existing isTimeSet() method unchanged
- Code checking isTimeSet() before using getEpochTime() continues to work
- New isTimeValid() is optional but recommended for security
- No breaking changes to existing functionality
Usage:
// For UI/display:
if (timeClient.isTimeSet()) {
Serial.println(timeClient.getFormattedTime());
}
// For security operations:
if (timeClient.isTimeValid()) {
generateAuthToken(timeClient.getEpochTime());
}
Fixes arduino-libraries#236
|
Memory usage change @ 8a3e6c6
Click for full report table
Click for full report CSV |
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.
This commit implements a two-layer security fix to address the vulnerability where getEpochTime() returned fabricated values (device uptime) before NTP synchronization completed.
Security Issue:
Layer 1 - Core Fix (getEpochTime):
Layer 2 - Enhanced Validation (isTimeValid):
Backward Compatibility:
Usage:
// For UI/display: if (timeClient.isTimeSet()) { Serial.println(timeClient.getFormattedTime()); }
// For security operations: if (timeClient.isTimeValid()) { generateAuthToken(timeClient.getEpochTime()); }
Fixes #236