mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-25 09:57:32 +09:00
Issue #2734 - Add base-64 grammar check to CSP nonces where applicable.
Resolves #2734
This commit is contained in:
parent
5ae40cfe47
commit
51022b98b2
3 changed files with 68 additions and 0 deletions
|
|
@ -61,6 +61,33 @@ isValidHexDig(char16_t aHexDig)
|
|||
(aHexDig >= 'a' && aHexDig <= 'f'));
|
||||
}
|
||||
|
||||
// Checks grammar for valid base-64 strings. Does not verify decodability.
|
||||
static bool
|
||||
isValidBase64Value(const char16_t* cur, const char16_t* end)
|
||||
{
|
||||
// Using grammar at https://w3c.github.io/webappsec-csp/#grammardef-nonce-source
|
||||
|
||||
// May end with one or two =
|
||||
if (end > cur && *(end-1) == EQUALS) end--;
|
||||
if (end > cur && *(end-1) == EQUALS) end--;
|
||||
|
||||
// Must have at least one character aside from any =
|
||||
if (end == cur) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Rest must all be A-Za-z0-9+/-_
|
||||
for (; cur < end; ++cur) {
|
||||
if (!(isCharacterToken(*cur) || isNumberToken(*cur) ||
|
||||
*cur == PLUS || *cur == SLASH ||
|
||||
*cur == DASH || *cur == UNDERLINE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================
|
||||
|
||||
namespace mozilla {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue