@zlink-systems/stream-wire 0.30.1 → 0.30.2
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.
|
@@ -97,10 +97,10 @@ function validateFrameworkJsonV1Value(value, schema, path, decode) {
|
|
|
97
97
|
if (typeof value !== 'string' || !BASE64_PATTERN.test(value)) {
|
|
98
98
|
schemaFailure(path, 'padded RFC 4648 base64');
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
if (encodeBase64(bytes) !== value)
|
|
100
|
+
if (!hasCanonicalBase64Padding(value))
|
|
102
101
|
schemaFailure(path, 'canonical padded RFC 4648 base64');
|
|
103
|
-
|
|
102
|
+
// decodeBase64 returns fresh storage owned by this value.
|
|
103
|
+
return decode ? decodeBase64(value) : value;
|
|
104
104
|
}
|
|
105
105
|
case 'enum':
|
|
106
106
|
if (typeof value !== 'string' || !schema.names.includes(value)) {
|
|
@@ -303,6 +303,20 @@ class JsonPropertyScanner {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
const BASE64_STRING_CHUNK_BYTES = 8192;
|
|
306
|
+
const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
307
|
+
/**
|
|
308
|
+
* Padded RFC 4648 text that matches BASE64_PATTERN is canonical exactly when
|
|
309
|
+
* the bits after the last encoded byte are zero: the low four bits of the
|
|
310
|
+
* symbol before `==`, or the low two bits of the symbol before `=`. Checking
|
|
311
|
+
* those bits replaces re-encoding the decoded bytes for comparison.
|
|
312
|
+
*/
|
|
313
|
+
function hasCanonicalBase64Padding(value) {
|
|
314
|
+
if (value.endsWith('=='))
|
|
315
|
+
return (BASE64_ALPHABET.indexOf(value.charAt(value.length - 3)) & 0x0f) === 0;
|
|
316
|
+
if (value.endsWith('='))
|
|
317
|
+
return (BASE64_ALPHABET.indexOf(value.charAt(value.length - 2)) & 0x03) === 0;
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
306
320
|
function encodeBase64(bytes) {
|
|
307
321
|
let binary = '';
|
|
308
322
|
for (let offset = 0; offset < bytes.length; offset += BASE64_STRING_CHUNK_BYTES) {
|