feat(sync): paginate Android sync with change tokens
This commit is contained in:
1 parent
0ff94f9b10
commit
97c237be80
76 files changed
+3401
-851
No files matched your search
@@ -60,16 +60,38 @@ export class Info {
|
||||
}
|
||||
}
|
||||
|
||||
/** Shortest SECRET a service accepts for its internal routes. */
|
||||
export const MIN_INTERNAL_SECRET_LENGTH = 16;
|
||||
|
||||
/**
|
||||
* True when the X-Internal-Auth value equals the configured secret. An unset
|
||||
* or empty secret never matches, and the comparison is constant-time.
|
||||
* Placeholders from .env.example files and the bare variable name. They are
|
||||
* public, so they never gate a route.
|
||||
*/
|
||||
export const EXAMPLE_INTERNAL_SECRETS = new Set(['SECRET', 'change-me-to-a-long-random-value']);
|
||||
|
||||
/**
|
||||
* True when the configured secret is strong enough to gate an internal route:
|
||||
* at least MIN_INTERNAL_SECRET_LENGTH characters and not an example
|
||||
* placeholder. Length counts characters, as the Python and Go helpers do.
|
||||
* @param {unknown} secret
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function internalSecretUsable(secret) {
|
||||
const value = String(secret ?? '');
|
||||
return [...value].length >= MIN_INTERNAL_SECRET_LENGTH && !EXAMPLE_INTERNAL_SECRETS.has(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the X-Internal-Auth value equals the configured secret. A secret
|
||||
* that is not usable (see internalSecretUsable) never matches, and the
|
||||
* comparison is constant-time.
|
||||
* @param {unknown} provided
|
||||
* @param {unknown} secret
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function internalSecretMatches(provided, secret) {
|
||||
const expected = Buffer.from(String(secret ?? ''));
|
||||
if (expected.length === 0) return false;
|
||||
if (!internalSecretUsable(secret)) return false;
|
||||
const expected = Buffer.from(String(secret));
|
||||
const actual = Buffer.from(String(provided ?? ''));
|
||||
return expected.length === actual.length && crypto.timingSafeEqual(expected, actual);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user