@everystack/auth 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/sql.ts +22 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everystack/auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "JWT authentication handlers, password hashing, and React auth context",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Scalable Technology, Inc. <licensing@scalable.technology>",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"bcryptjs": "3.0.3",
|
|
94
|
-
"@everystack/model": "0.4.
|
|
94
|
+
"@everystack/model": "0.4.11"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"@everystack/api": ">=0.1.0",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"postgres": "3.4.9",
|
|
121
121
|
"ts-jest": "29.4.9",
|
|
122
122
|
"typescript": "5.9.3",
|
|
123
|
-
"@everystack/api": "0.
|
|
123
|
+
"@everystack/api": "0.4.0"
|
|
124
124
|
},
|
|
125
125
|
"scripts": {
|
|
126
126
|
"test": "jest",
|
package/src/sql.ts
CHANGED
|
@@ -37,7 +37,8 @@ AS $$
|
|
|
37
37
|
BEGIN
|
|
38
38
|
RETURN crypt(p_password, gen_salt('bf', 10));
|
|
39
39
|
END;
|
|
40
|
-
|
|
40
|
+
$$;
|
|
41
|
+
REVOKE EXECUTE ON FUNCTION auth.hash_password FROM PUBLIC;`;
|
|
41
42
|
|
|
42
43
|
const VERIFY_PASSWORD = `\
|
|
43
44
|
CREATE OR REPLACE FUNCTION auth.verify_password(p_password TEXT, p_hash TEXT)
|
|
@@ -54,7 +55,8 @@ BEGIN
|
|
|
54
55
|
v_normalized := regexp_replace(p_hash, '^\\$2[by]\\$', '$2a$');
|
|
55
56
|
RETURN crypt(p_password, v_normalized) = v_normalized;
|
|
56
57
|
END;
|
|
57
|
-
|
|
58
|
+
$$;
|
|
59
|
+
REVOKE EXECUTE ON FUNCTION auth.verify_password FROM PUBLIC;`;
|
|
58
60
|
|
|
59
61
|
const SIGN_JWT = `\
|
|
60
62
|
CREATE OR REPLACE FUNCTION auth.sign_jwt(p_payload JSONB)
|
|
@@ -98,7 +100,8 @@ BEGIN
|
|
|
98
100
|
|
|
99
101
|
RETURN v_signing_input || '.' || v_signature;
|
|
100
102
|
END;
|
|
101
|
-
|
|
103
|
+
$$;
|
|
104
|
+
REVOKE EXECUTE ON FUNCTION auth.sign_jwt FROM PUBLIC;`;
|
|
102
105
|
|
|
103
106
|
const VERIFY_JWT = `\
|
|
104
107
|
CREATE OR REPLACE FUNCTION auth.verify_jwt(p_token TEXT)
|
|
@@ -156,7 +159,8 @@ BEGIN
|
|
|
156
159
|
|
|
157
160
|
RETURN v_payload_json;
|
|
158
161
|
END;
|
|
159
|
-
|
|
162
|
+
$$;
|
|
163
|
+
REVOKE EXECUTE ON FUNCTION auth.verify_jwt FROM PUBLIC;`;
|
|
160
164
|
|
|
161
165
|
// =============================================================================
|
|
162
166
|
// REFRESH TOKEN FUNCTIONS (RFC 6819)
|
|
@@ -391,6 +395,11 @@ REVOKE EXECUTE ON FUNCTION auth.cleanup_refresh_tokens FROM PUBLIC;`;
|
|
|
391
395
|
// SUPABASE-COMPATIBLE ACCESSOR FUNCTIONS
|
|
392
396
|
// =============================================================================
|
|
393
397
|
|
|
398
|
+
// The three accessors are SECURITY INVOKER and are called FROM RLS POLICY EXPRESSIONS, which
|
|
399
|
+
// evaluate as the querying role. So PUBLIC comes off — no blanket grant — and the everystack
|
|
400
|
+
// role chain is granted back explicitly. A bare `REVOKE ... FROM PUBLIC` with no grant-back
|
|
401
|
+
// would break every policy that calls them, which is exactly why they must not be lumped in
|
|
402
|
+
// with the internal SECDEF helpers below.
|
|
394
403
|
const AUTH_UID = `\
|
|
395
404
|
CREATE OR REPLACE FUNCTION auth.uid()
|
|
396
405
|
RETURNS uuid
|
|
@@ -400,7 +409,9 @@ AS $$
|
|
|
400
409
|
(nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'sub')::uuid,
|
|
401
410
|
NULL
|
|
402
411
|
);
|
|
403
|
-
|
|
412
|
+
$$;
|
|
413
|
+
REVOKE EXECUTE ON FUNCTION auth.uid FROM PUBLIC;
|
|
414
|
+
GRANT EXECUTE ON FUNCTION auth.uid() TO anon, authenticated, admin;`;
|
|
404
415
|
|
|
405
416
|
const AUTH_ROLE = `\
|
|
406
417
|
CREATE OR REPLACE FUNCTION auth.role()
|
|
@@ -411,7 +422,9 @@ AS $$
|
|
|
411
422
|
nullif(current_setting('request.jwt.claims', true), '')::jsonb ->> 'role',
|
|
412
423
|
'anon'
|
|
413
424
|
);
|
|
414
|
-
|
|
425
|
+
$$;
|
|
426
|
+
REVOKE EXECUTE ON FUNCTION auth.role FROM PUBLIC;
|
|
427
|
+
GRANT EXECUTE ON FUNCTION auth.role() TO anon, authenticated, admin;`;
|
|
415
428
|
|
|
416
429
|
const AUTH_JWT = `\
|
|
417
430
|
CREATE OR REPLACE FUNCTION auth.jwt()
|
|
@@ -422,7 +435,9 @@ AS $$
|
|
|
422
435
|
nullif(current_setting('request.jwt.claims', true), '')::jsonb,
|
|
423
436
|
'{}'::jsonb
|
|
424
437
|
);
|
|
425
|
-
|
|
438
|
+
$$;
|
|
439
|
+
REVOKE EXECUTE ON FUNCTION auth.jwt FROM PUBLIC;
|
|
440
|
+
GRANT EXECUTE ON FUNCTION auth.jwt() TO anon, authenticated, admin;`;
|
|
426
441
|
|
|
427
442
|
// =============================================================================
|
|
428
443
|
// ONE-TIME TOKEN FUNCTIONS
|