Skip to content

Commit fd9fc48

Browse files
committed
Ignore protected props in create new session
1 parent f27831e commit fd9fc48

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Changes
1717

1818
- Dashboard APIs now return a status code `403` for all non-GET requests if the currently logged in Dashboard User is not listed in the `admins` array
19+
- Now ignoring protected props in the payload in `CreateNewSession` and `CreateNewSessionWithoutRequestResponse`
1920

2021
## [0.13.2] - 2023-08-28
2122

recipe/session/accessTokenVersions_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,21 @@ func TestShouldThrowErrorWhenUsingProtectedProps(t *testing.T) {
184184
}
185185
res2, err2 := http.Post(testServer.URL+"/create", "application/json", bytes.NewBuffer(postBody))
186186
if err2 != nil {
187-
t.Error(err.Error())
187+
t.Error(err2.Error())
188188
}
189189

190-
assert.Equal(t, 400, res2.StatusCode)
190+
assert.Equal(t, 200, res2.StatusCode)
191191
cookies := unittesting.ExtractInfoFromResponse(res2)
192-
assert.True(t, cookies["accessTokenFromAny"] == "")
193-
assert.True(t, cookies["refreshTokenFromAny"] == "")
194-
assert.True(t, cookies["frontToken"] == "")
192+
assert.False(t, cookies["accessTokenFromAny"] == "")
193+
assert.False(t, cookies["refreshTokenFromAny"] == "")
194+
assert.False(t, cookies["frontToken"] == "")
195+
196+
parsedToken, err := ParseJWTWithoutSignatureVerification(cookies["accessTokenFromAny"])
197+
if err != nil {
198+
t.Error(err.Error())
199+
}
200+
201+
assert.True(t, parsedToken.Payload["sub"] != "asdf")
195202
}
196203

197204
func TestMergeIntoATShouldHelpMigratingV2TokenUsingProtectedProps(t *testing.T) {

recipe/session/constants.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@ const (
3131
CookieSameSite_LAX = "lax"
3232
CookieSameSite_STRICT = "strict"
3333
)
34+
35+
var JWKCacheMaxAgeInMs int64 = 60000
36+
var JWKRefreshRateLimit = 500
37+
var protectedProps = []string{
38+
"sub",
39+
"iat",
40+
"exp",
41+
"sessionHandle",
42+
"parentRefreshTokenHash1",
43+
"refreshTokenHash1",
44+
"antiCsrfToken",
45+
"rsub",
46+
"tId",
47+
}

recipe/session/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func CreateNewSessionWithoutRequestResponse(tenantId string, userID string, acce
6464

6565
finalAccessTokenPayload["iss"] = issuer
6666

67+
for _, protectedProp := range protectedProps {
68+
delete(finalAccessTokenPayload, protectedProp)
69+
}
70+
6771
for _, claim := range claimsAddedByOtherRecipes {
6872
finalAccessTokenPayload, err = claim.Build(userID, tenantId, finalAccessTokenPayload, userContext[0])
6973
if err != nil {

recipe/session/recipeImplementation.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,6 @@ import (
3232
"github.com/supertokens/supertokens-golang/supertokens"
3333
)
3434

35-
var protectedProps = []string{
36-
"sub",
37-
"iat",
38-
"exp",
39-
"sessionHandle",
40-
"parentRefreshTokenHash1",
41-
"refreshTokenHash1",
42-
"antiCsrfToken",
43-
"tId",
44-
}
45-
46-
var JWKCacheMaxAgeInMs int64 = 60000
47-
var JWKRefreshRateLimit = 500
4835
var jwksCache *sessmodels.GetJWKSResult = nil
4936
var mutex sync.RWMutex
5037

recipe/session/sessionRequestFunctions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func CreateNewSessionInRequest(req *http.Request, res http.ResponseWriter, tenan
4343
issuer := appInfo.APIDomain.GetAsStringDangerous() + appInfo.APIBasePath.GetAsStringDangerous()
4444
finalAccessTokenPayload["iss"] = issuer
4545

46+
for _, protectedProp := range protectedProps {
47+
delete(finalAccessTokenPayload, protectedProp)
48+
}
49+
4650
for _, claim := range claimsAddedByOtherRecipes {
4751
_finalAccessTokenPayload, err := claim.Build(userID, tenantId, finalAccessTokenPayload, userContext)
4852
if err != nil {

0 commit comments

Comments
 (0)