Skip to content

Conversation

@vhatuncev
Copy link

var serverClock = TimeSpan.FromTicks(DateTime.UtcNow.Ticks);
var requestClock = TimeSpan.FromTicks(DateTime.UtcNow.AddSeconds(1).Ticks);

var serverTime = Convert.ToUInt64(serverClock.TotalSeconds);
var requestTime = Convert.ToUInt64(requestClock.TotalSeconds);

Console.WriteLine(serverTime - requestTime);

 var serverClock = TimeSpan.FromTicks(DateTime.UtcNow.Ticks);
            var requestClock = TimeSpan.FromTicks(DateTime.UtcNow.AddSeconds(1).Ticks);

            var serverTime = Convert.ToUInt64(serverClock.TotalSeconds);
            var requestTime = Convert.ToUInt64(requestClock.TotalSeconds);

            Console.WriteLine(serverTime - requestTime);
@vhatuncev
Copy link
Author

need additional check for requestTotalSeconds variable
for example if requestTotalSeconds more on one second(because request host has different time),
result of statement serverTotalSeconds - requestTotalSeconds
will be very big value and not negative as expected so all request will treated as reply attack and rejected check code in comment for this file.
suggestion is - convert to signed integer, so even if request local time will be far away from server time it will

@saipuli
Copy link

saipuli commented Dec 20, 2016

I ran into the same issue, but used
Math.Abs((Int64)(serverTotalSeconds - requestTotalSeconds)) > requestMaxAgeInSeconds
I used Abs because I wanted to discourage clients with clocks that are way out of sync from calling my apis.

@vhatuncev
Copy link
Author

Well, it can save you, but not more then requestMaxAgeInSeconds, if clients out of sync for hours you still get the error.
Another thing, it saves you only if clients have local time in future, relatively from server, if client clocks will be in the past, relatively from server, it won't help.

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.

2 participants