Ignore improperly formatted armor headers (#1557)

Show a debug warning instead of throwing an error on malformed headers.
This commit is contained in:
Celine Moredo
2022-08-22 21:30:33 +08:00
committed by GitHub
parent 93644b7c58
commit 4d2cf85a51
2 changed files with 9 additions and 14 deletions

View File

@@ -182,15 +182,17 @@ function createcrc24(input) {
}
/**
* Verify armored headers. RFC4880, section 6.3: "OpenPGP should consider improperly formatted
* Armor Headers to be corruption of the ASCII Armor."
* Verify armored headers. crypto-refresh-06, section 6.2:
* "An OpenPGP implementation may consider improperly formatted Armor
* Headers to be corruption of the ASCII Armor, but SHOULD make an
* effort to recover."
* @private
* @param {Array<String>} headers - Armor headers
*/
function verifyHeaders(headers) {
for (let i = 0; i < headers.length; i++) {
if (!/^([^\s:]|[^\s:][^:]*[^\s:]): .+$/.test(headers[i])) {
throw new Error('Improperly formatted armor header: ' + headers[i]);
util.printDebugError(new Error('Improperly formatted armor header: ' + headers[i]));
}
if (!/^(Version|Comment|MessageID|Hash|Charset): .+$/.test(headers[i])) {
util.printDebugError(new Error('Unknown header: ' + headers[i]));