Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

0xFirekeeper
Copy link
Member

@0xFirekeeper 0xFirekeeper commented Sep 11, 2025

Updated date formatting and parsing in AWS authentication to explicitly use System.Globalization.CultureInfo.InvariantCulture and DateTimeStyles.AssumeUniversal. This ensures consistent behavior regardless of system locale.

Closes BLD-298


PR-Codex overview

This PR focuses on improving the date formatting in the AWS.cs file by ensuring that date strings are consistently formatted using System.Globalization.CultureInfo.InvariantCulture.

Detailed summary

  • Updated amzDate and dateStamp to use CultureInfo.InvariantCulture for string formatting.
  • Modified the serverTime parsing to include DateTimeStyles.AssumeUniversal for accurate time interpretation.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes

    • Resolved authentication failures caused by locale-specific date formatting.
    • Fixed intermittent “signature expired” errors by correctly interpreting server time as UTC during retries.
  • Reliability

    • Standardized time handling to be culture-invariant, ensuring consistent request signing across regions and reducing false expiration errors.

Updated date formatting and parsing in AWS authentication to explicitly use System.Globalization.CultureInfo.InvariantCulture and DateTimeStyles.AssumeUniversal. This ensures consistent behavior regardless of system locale.

Closes BLD-298
Copy link

linear bot commented Sep 11, 2025

Copy link

coderabbitai bot commented Sep 11, 2025

Walkthrough

Culture-invariant formatting was applied to AWS date strings, and server time parsing in the signature-expired retry path was adjusted to treat parsed times as UTC using DateTimeStyles.AssumeUniversal.

Changes

Cohort / File(s) Summary
AWS signing date handling
Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Authentication/AWS.cs
Use CultureInfo.InvariantCulture for amzDate/dateStamp formatting; change server time ParseExact to use DateTimeStyles.AssumeUniversal in retry after signature-expired response.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant AWSAuth as AWS Auth Helper
  participant AWSSvc as AWS Service

  rect rgba(200,220,255,0.25)
    note right of AWSAuth: Build signed request (culture-invariant date formatting)
    Client->>AWSAuth: Prepare request
    AWSAuth->>AWSSvc: Send signed request
  end

  alt Success
    AWSSvc-->>AWSAuth: 200 OK
    AWSAuth-->>Client: Response
  else Signature expired
    AWSSvc-->>AWSAuth: 403 SignatureExpired + ServerTime
    note right of AWSAuth: Parse ServerTime as UTC (AssumeUniversal)
    AWSAuth->>AWSSvc: Re-sign and retry
    AWSSvc-->>AWSAuth: Response
    AWSAuth-->>Client: Response
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed This title succinctly and accurately describes the primary change: switching AWS date formatting and parsing to use an invariant culture. It is concise, specific, and free of noise or vague wording, so a teammate scanning the PR list can understand the main intent. Therefore the title aligns well with the changes shown in the diff.
Linked Issues Check ✅ Passed The PR implements CultureInfo.InvariantCulture for amzDate and dateStamp formatting and changes server time parsing to use DateTimeStyles.AssumeUniversal instead of ToUniversalTime(), which directly addresses BLD-298's objective to avoid locale/calendar-dependent datetime issues. The changes are focused on formatting/parsing logic and do not alter public signatures, matching the linked issue's coding requirement. Based on the provided summary and PR metadata (which states it closes BLD-298), the code changes satisfy the linked issue.
Out of Scope Changes Check ✅ Passed The raw summary shows only formatting and parsing edits in Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Authentication/AWS.cs and indicates no changes to exported or public entities, so there are no apparent out-of-scope changes. The modifications are narrowly scoped to CultureInfo.InvariantCulture and DateTimeStyles.AssumeUniversal usage. Therefore the PR appears limited to the linked issue's intent.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch firekeeper/culture

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Authentication/AWS.cs (2)

178-186: Treating server time as UTC is correct; add a bounds check and (optionally) AdjustToUniversal

Current substring can throw if AWS changes error text shape. Guard length before Substring; also consider AdjustToUniversal (harmless with ‘Z’ input) for completeness.

-                var idx = responseContent.LastIndexOf('(');
-                if (idx > -1)
-                {
-                    var parsedTimeString = responseContent.Substring(idx + 1, amzDate.Length);
-                    var serverTime = DateTime.ParseExact(parsedTimeString, amzDateFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal);
+                var idx = responseContent.LastIndexOf('(');
+                if (idx > -1 && idx + 1 + amzDate.Length <= responseContent.Length)
+                {
+                    var parsedTimeString = responseContent.Substring(idx + 1, amzDate.Length);
+                    var serverTime = DateTime.ParseExact(
+                        parsedTimeString,
+                        amzDateFormat,
+                        System.Globalization.CultureInfo.InvariantCulture,
+                        System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);

229-231: Hex formatting: align with invariant push (nit)

AppendFormat defaults to current culture. It’s already safe for “x2”, but using InvariantCulture keeps the file consistently culture-agnostic.

-            _ = hex.AppendFormat("{0:x2}", b);
+            _ = hex.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "{0:x2}", b);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between df77184 and 2ed36aa.

📒 Files selected for processing (1)
  • Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Authentication/AWS.cs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-test-cov
🔇 Additional comments (1)
Thirdweb/Thirdweb.Wallets/InAppWallet/EmbeddedWallet.Authentication/AWS.cs (1)

135-136: Invariant culture for SigV4 timestamps — LGTM

Using CultureInfo.InvariantCulture for amzDate and dateStamp is correct and prevents locale/calendar-induced breakage.

@0xFirekeeper 0xFirekeeper merged commit 97af148 into main Sep 11, 2025
3 of 4 checks passed
@0xFirekeeper 0xFirekeeper deleted the firekeeper/culture branch September 11, 2025 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant