forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add token prefixes to session and logout tokens (ory#3132)
This feature adds token prefixes to Ory session and logout tokens: * `ory_st_`: Ory session token prefix * `ory_lt_`: Logout token prefix
- Loading branch information
Showing
19 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
persistence/sql/migratest/fixtures/session/068f6bb6-d15f-436d-94f7-b3fd0489c9ef.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"id": "068f6bb6-d15f-436d-94f7-b3fd0489c9ef", | ||
"active": false, | ||
"expires_at": "2013-10-07T08:23:19Z", | ||
"authenticated_at": "2013-10-07T08:23:19Z", | ||
"authenticator_assurance_level": "aal2", | ||
"authentication_methods": [ | ||
{ | ||
"method": "password", | ||
"aal": "", | ||
"completed_at": "0001-01-01T00:00:00Z" | ||
}, | ||
{ | ||
"method": "totp", | ||
"aal": "", | ||
"completed_at": "0001-01-01T00:00:00Z" | ||
} | ||
], | ||
"issued_at": "2013-10-07T08:23:19Z", | ||
"identity": { | ||
"id": "5ff66179-c240-4703-b0d8-494592cefff5", | ||
"schema_id": "default", | ||
"schema_url": "https://www.ory.sh/schemas/ZGVmYXVsdA", | ||
"state": "active", | ||
"traits": { | ||
"email": "[email protected]" | ||
}, | ||
"verifiable_addresses": [ | ||
{ | ||
"id": "45e867e9-2745-4f16-8dd4-84334a252b61", | ||
"value": "[email protected]", | ||
"verified": false, | ||
"via": "email", | ||
"status": "pending", | ||
"created_at": "2013-10-07T08:23:19Z", | ||
"updated_at": "2013-10-07T08:23:19Z" | ||
} | ||
], | ||
"metadata_public": null, | ||
"created_at": "2013-10-07T08:23:19Z", | ||
"updated_at": "2013-10-07T08:23:19Z" | ||
}, | ||
"devices": [] | ||
} |
This file contains 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
6 changes: 6 additions & 0 deletions
6
persistence/sql/migratest/testdata/20230313141439_testdata.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
INSERT INTO sessions (id, nid, issued_at, expires_at, authenticated_at, created_at, updated_at, token, identity_id, | ||
active, logout_token, aal, authentication_methods) | ||
VALUES ('068f6bb6-d15f-436d-94f7-b3fd0489c9ef', '884f556e-eb3a-4b9f-bee3-11345642c6c0', '2013-10-07 08:23:19', | ||
'2013-10-07 08:23:19', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '2013-10-07 08:23:19', | ||
'ory_lo_5e5aad0f7a4143452df3d23733a68e3', '5ff66179-c240-4703-b0d8-494592cefff5', true, 'ory_st_5e5aad0f7a4143452df3d23733a68e2', 'aal2', | ||
'[{"method":"password"},{"method":"totp"}]'); |
5 changes: 5 additions & 0 deletions
5
persistence/sql/migrations/sql/20230313141439000000_session_token_length.cockroach.down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- Downsizing is not yet supported in CockroachDB. Since this migration has no real-world impact on the application, we can safely | ||
-- not execute it. | ||
-- | ||
-- ALTER TABLE sessions ALTER COLUMN token TYPE varchar(32); | ||
-- ALTER TABLE sessions ALTER COLUMN logout_token TYPE varchar(32); |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/sql/20230313141439000000_session_token_length.down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE sessions ALTER COLUMN token TYPE varchar(32); | ||
ALTER TABLE sessions ALTER COLUMN logout_token TYPE varchar(32); |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/sql/20230313141439000000_session_token_length.mysql.down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE sessions MODIFY COLUMN token varchar(32) NULL; | ||
ALTER TABLE sessions MODIFY COLUMN logout_token varchar(32) NULL; |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/sql/20230313141439000000_session_token_length.mysql.up.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE sessions MODIFY COLUMN token varchar(39) NULL; | ||
ALTER TABLE sessions MODIFY COLUMN logout_token varchar(39) NULL; |
29 changes: 29 additions & 0 deletions
29
persistence/sql/migrations/sql/20230313141439000000_session_token_length.sqlite3.down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
DROP INDEX sessions_token_uq_idx; | ||
DROP INDEX sessions_logout_token_uq_idx; | ||
DROP INDEX sessions_token_nid_idx; | ||
|
||
ALTER TABLE sessions RENAME COLUMN token TO old_token; | ||
ALTER TABLE sessions RENAME COLUMN logout_token TO old_logout_token; | ||
|
||
ALTER TABLE sessions | ||
ADD COLUMN token varchar(32) NULL; | ||
ALTER TABLE sessions | ||
ADD COLUMN logout_token varchar(32) NULL; | ||
|
||
UPDATE sessions | ||
SET token = old_token | ||
WHERE true; | ||
|
||
UPDATE sessions | ||
SET logout_token = old_logout_token | ||
WHERE true; | ||
|
||
ALTER TABLE sessions | ||
DROP COLUMN old_token; | ||
|
||
ALTER TABLE sessions | ||
DROP COLUMN old_logout_token; | ||
|
||
CREATE UNIQUE INDEX sessions_token_uq_idx ON sessions (logout_token); | ||
CREATE UNIQUE INDEX sessions_logout_token_uq_idx ON sessions (token); | ||
CREATE INDEX sessions_token_nid_idx ON sessions (nid, token); |
27 changes: 27 additions & 0 deletions
27
persistence/sql/migrations/sql/20230313141439000000_session_token_length.sqlite3.up.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
DROP INDEX sessions_token_uq_idx; | ||
DROP INDEX sessions_logout_token_uq_idx; | ||
DROP INDEX sessions_token_nid_idx; | ||
|
||
ALTER TABLE sessions RENAME COLUMN token TO old_token; | ||
ALTER TABLE sessions RENAME COLUMN logout_token TO old_logout_token; | ||
ALTER TABLE sessions | ||
ADD COLUMN token varchar(39) NULL; | ||
ALTER TABLE sessions | ||
ADD COLUMN logout_token varchar(39) NULL; | ||
|
||
UPDATE sessions | ||
SET token = old_token | ||
WHERE true; | ||
|
||
UPDATE sessions | ||
SET logout_token = old_logout_token | ||
WHERE true; | ||
|
||
ALTER TABLE sessions | ||
DROP COLUMN old_token; | ||
ALTER TABLE sessions | ||
DROP COLUMN old_logout_token; | ||
|
||
CREATE UNIQUE INDEX sessions_token_uq_idx ON sessions (logout_token); | ||
CREATE UNIQUE INDEX sessions_logout_token_uq_idx ON sessions (token); | ||
CREATE INDEX sessions_token_nid_idx ON sessions (nid, token); |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/sql/20230313141439000000_session_token_length.up.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE sessions ALTER COLUMN token TYPE varchar(39); | ||
ALTER TABLE sessions ALTER COLUMN logout_token TYPE varchar(39); |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/sql/20230313141439000001_session_token_length.down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
UPDATE sessions SET token = LEFT(token, 32) WHERE TRUE; | ||
UPDATE sessions SET logout_token = LEFT(logout_token, 32) WHERE TRUE; |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/sql/20230313141439000001_session_token_length.sqlite3.down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
UPDATE sessions SET token = substr(token, 0, 32) WHERE TRUE; | ||
UPDATE sessions SET logout_token = substr(logout_token, 0, 32) WHERE TRUE; |
1 change: 1 addition & 0 deletions
1
persistence/sql/migrations/sql/20230313141439000001_session_token_length.up.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package x | ||
|
||
const OrySessionToken = "ory_st_" | ||
const OryLogoutToken = "ory_lo_" |