Skip to content

Commit

Permalink
implement ss2022 client timestamp check as per spec
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Nov 19, 2023
1 parent 1c9cace commit 12b4065
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions proxy/shadowsocks2022/client_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func (c *ClientUDPSession) KeepReading() {
newError("unable to decode udp response").Base(err).WriteToLog()
continue
}

{
timeDifference := int64(udpResp.TimeStamp) - time.Now().Unix()
if timeDifference < -30 || timeDifference > 30 {
newError("udp packet timestamp difference too large, packet discarded").WriteToLog()
continue
}
}

c.locker.Lock()
session, ok := c.sessionMap[string(udpResp.ClientSessionID[:])]
if ok {
Expand Down
2 changes: 1 addition & 1 deletion proxy/shadowsocks2022/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (t *TCPRequest) DecodeTCPResponseHeader(effectivePsk []byte, In io.Reader)
return newError("unexpected TCP header type")
}
timeDifference := int64(fixedLengthHeader.Timestamp) - time.Now().Unix()
if timeDifference < -60 || timeDifference > 60 {
if timeDifference < -30 || timeDifference > 30 {
return newError("timestamp is too far away")
}

Expand Down

0 comments on commit 12b4065

Please sign in to comment.