@@ -71,6 +71,63 @@ describe("cookieScope", () => {
7171} ) ;
7272
7373describe ( "readChromiumCookieDatabase" , ( ) => {
74+ it . effect . each ( [ 14 , 24 ] ) (
75+ "reads mixed TEXT and BLOB encrypted values in schema %i without losing bytes" ,
76+ ( schemaVersion ) =>
77+ Effect . gen ( function * ( ) {
78+ const fileSystem = yield * FileSystem . FileSystem ;
79+ const directory = yield * fileSystem . makeTempDirectoryScoped ( {
80+ prefix : "t3code-chromium-storage-types-" ,
81+ } ) ;
82+ const filename = `${ directory } /Cookies` ;
83+ const key = Buffer . from ( "0123456789abcdef" ) ;
84+ const host = ".example.test" ;
85+ const value = "stored encrypted value" ;
86+ const payload =
87+ schemaVersion >= 24
88+ ? Buffer . concat ( [
89+ NodeCrypto . createHash ( "sha256" ) . update ( host ) . digest ( ) ,
90+ Buffer . from ( value ) ,
91+ ] )
92+ : Buffer . from ( value ) ;
93+ const encrypted = encryptV10 ( payload , key ) ;
94+
95+ yield * Effect . gen ( function * ( ) {
96+ const sql = yield * SqlClient . SqlClient ;
97+ yield * sql `create table meta (key text primary key, value text not null)` ;
98+ yield * sql `insert into meta values ('version', ${ schemaVersion } )` ;
99+ yield * sql `create table cookies (
100+ host_key text not null, name text not null, value text not null,
101+ encrypted_value blob not null, path text not null, expires_utc integer not null,
102+ is_secure integer not null, is_httponly integer not null, samesite integer not null
103+ )` ;
104+ if ( schemaVersion >= 15 ) {
105+ yield * sql `alter table cookies add column top_frame_site_key text not null default ''` ;
106+ }
107+ yield * sql `insert into cookies
108+ (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, samesite) values
109+ (${ host } , 'plaintext', 'stored plaintext', '', '/', 0, 0, 0, -1),
110+ (${ host } , 'text-encrypted', '', cast(${ encrypted } as text), '/', 0, 1, 1, 2),
111+ (${ host } , 'blob-encrypted', '', ${ encrypted } , '/', 0, 1, 1, 2)` ;
112+ const storageTypes = yield * sql `select typeof(encrypted_value) as storage_type
113+ from cookies order by name` ;
114+ expect ( storageTypes ) . toEqual ( [
115+ { storage_type : "blob" } ,
116+ { storage_type : "text" } ,
117+ { storage_type : "text" } ,
118+ ] ) ;
119+ } ) . pipe ( Effect . provide ( NodeSqliteClient . layer ( { filename } ) ) ) ;
120+
121+ const result = yield * readChromiumCookieDatabase ( filename , { cbcV10 : key } , "darwin" ) ;
122+ expect ( result . undecryptable ) . toBe ( 0 ) ;
123+ expect ( result . cookies . map ( ( cookie ) => [ cookie . name , cookie . value ] ) ) . toEqual ( [
124+ [ "plaintext" , "stored plaintext" ] ,
125+ [ "text-encrypted" , value ] ,
126+ [ "blob-encrypted" , value ] ,
127+ ] ) ;
128+ } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
129+ ) ;
130+
74131 it ( "decrypts Windows v10 AES-GCM records and rejects app-bound v20 records" , ( ) => {
75132 const key = Buffer . from ( "0123456789abcdef0123456789abcdef" ) ;
76133 const host = ".example.test" ;
0 commit comments