Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: Added option to try to sanitize a modified subject if verification fails #469

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion chrome/content/options_advanced.xul
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
<preference id="pref_error.algorithm.rsa.weakKeyLength.treatAs"
name="extensions.dkim_verifier.error.algorithm.rsa.weakKeyLength.treatAs"
type="int"/>
<preference id="pref_error.sanitizeSubject"
name="extensions.dkim_verifier.error.sanitizeSubject"
type="bool"/>
</preferences>

<checkbox preference="pref_debug" label="&debug.label;"/>
<checkbox preference="pref_error.detailedReasons" label="&error.detailedReasons.label;"/>
<checkbox preference="pref_error.key_testmode.ignore"
Expand All @@ -51,6 +54,8 @@
label="&arh.replaceAddonResult.label;"/>
<checkbox preference="pref_arh.relaxedParsing"
label="&arh.relaxedParsing.label;"/>
<checkbox preference="pref_error.sanitizeSubject"
label="&error.sanitizeSubject.label;"/>
<hbox align="center">
<label>&error.illformed_i.treatAs.label;</label>
<menulist preference="pref_error.illformed_i.treatAs">
Expand Down
2 changes: 2 additions & 0 deletions chrome/locale/de/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_AUID = Absender passt nicht zur Benutzeridentität

# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Kopfzeile '%S' ist nicht signiert

DKIM_SIGERROR_SUBJECT_MODIFIED = Der Betreff wurde verändert: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/de/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Tolerant">
<!ENTITY policy.unsigned_header.mode.value.1.label "Empfohlen">
<!ENTITY policy.unsigned_header.mode.value.2.label "Streng">

<!ENTITY error.sanitizeSubject.label "Versuche Ergänzungen im Betreff zu korrigieren">
2 changes: 2 additions & 0 deletions chrome/locale/en-US/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_AUID = From does not match the user identifier

# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Header '%S' is not signed

DKIM_SIGERROR_SUBJECT_MODIFIED = Subject was modified: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/en-US/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Relaxed">
<!ENTITY policy.unsigned_header.mode.value.1.label "Recommended">
<!ENTITY policy.unsigned_header.mode.value.2.label "Strict">

<!ENTITY error.sanitizeSubject.label "Try to remove amendments in the subject">
2 changes: 2 additions & 0 deletions chrome/locale/fr/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_AUID = L'expéditeur ne correspond pas avec l'identi

# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Header '%S' is not signed

DKIM_SIGERROR_SUBJECT_MODIFIED = Subject was modified: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/fr/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Relaxed">
<!ENTITY policy.unsigned_header.mode.value.1.label "Recommended">
<!ENTITY policy.unsigned_header.mode.value.2.label "Strict">

<!ENTITY error.sanitizeSubject.label "Try to remove amendments in the subject">
2 changes: 2 additions & 0 deletions chrome/locale/hu/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_AUID = A feladó nem egyezik a felhasználói azonos

# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Header '%S' is not signed

DKIM_SIGERROR_SUBJECT_MODIFIED = Subject was modified: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/hu/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Relaxed">
<!ENTITY policy.unsigned_header.mode.value.1.label "Recommended">
<!ENTITY policy.unsigned_header.mode.value.2.label "Strict">

<!ENTITY error.sanitizeSubject.label "Try to remove amendments in the subject">
2 changes: 2 additions & 0 deletions chrome/locale/it/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_AUID = Il mittente non corrisponde all’identificat

# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Header '%S' is not signed

DKIM_SIGERROR_SUBJECT_MODIFIED = Subject was modified: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/it/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Relaxed">
<!ENTITY policy.unsigned_header.mode.value.1.label "Recommended">
<!ENTITY policy.unsigned_header.mode.value.2.label "Strict">

<!ENTITY error.sanitizeSubject.label "Try to remove amendments in the subject">
2 changes: 2 additions & 0 deletions chrome/locale/ja-JP/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_AUID = 差出人がユーザ識別子とマッチし

# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Header '%S' is not signed

DKIM_SIGERROR_SUBJECT_MODIFIED = Subject was modified: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/ja-JP/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Relaxed">
<!ENTITY policy.unsigned_header.mode.value.1.label "Recommended">
<!ENTITY policy.unsigned_header.mode.value.2.label "Strict">

<!ENTITY error.sanitizeSubject.label "Try to remove amendments in the subject">
2 changes: 2 additions & 0 deletions chrome/locale/zh-CN/dkim.properties
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ DKIM_SIGWARNING_FROM_NOT_IN_SDID=From 不在签名域中
DKIM_SIGWARNING_FROM_NOT_IN_AUID=From 不匹配用户标识符
# DKIM_SIGWARNING - POLICY
DKIM_SIGWARNING_UNSIGNED_HEADER = Header '%S' is not signed

DKIM_SIGERROR_SUBJECT_MODIFIED = Subject was modified: '%S'
2 changes: 2 additions & 0 deletions chrome/locale/zh-CN/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@
<!ENTITY policy.unsigned_header.mode.value.0.label "Relaxed">
<!ENTITY policy.unsigned_header.mode.value.1.label "Recommended">
<!ENTITY policy.unsigned_header.mode.value.2.label "Strict">

<!ENTITY error.sanitizeSubject.label "Try to remove amendments in the subject">
4 changes: 2 additions & 2 deletions defaults/preferences/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pref("extensions.dkim_verifier.policy.DMARC.shouldBeSigned.neededPolicy", "none"

pref("extensions.dkim_verifier.display.favicon.show", true);

/*
/*
* Mode to handle headers, which should be signed, but are not
* 10 relaxed
* 20 recommended
Expand Down Expand Up @@ -145,7 +145,7 @@ pref("extensions.dkim_verifier.error.key_testmode.ignore", false);
pref("extensions.dkim_verifier.error.contentTypeCharsetAddedQuotes.treatAs", 0);
pref("extensions.dkim_verifier.error.algorithm.sign.rsa-sha1.treatAs", 1);
pref("extensions.dkim_verifier.error.algorithm.rsa.weakKeyLength.treatAs", 2);

pref("extensions.dkim_verifier.error.sanitizeSubject", false);

////////////////////////////////////////////////////////////////////////////////
// account specific options
Expand Down
53 changes: 42 additions & 11 deletions modules/dkimVerifier.jsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,31 +1209,62 @@ var Verifier = (function() {

var isValid = verifyFunction(DKIMSignature.DKIMKey.p, headerHashInput, DKIMSignature.a_hash,
DKIMSignature.b, DKIMSignature.warnings, keyInfo);
if (!isValid) {
if (prefs.getIntPref("error.contentTypeCharsetAddedQuotes.treatAs") > 0) {
log.debug("Try with removed quotes in Content-Type charset.");
msg.headerFields.get("content-type")[0] =
msg.headerFields.get("content-type")[0].
replace(/charset="([^"]+)"/i, "charset=$1");

if (!isValid && prefs.getIntPref("error.contentTypeCharsetAddedQuotes.treatAs") > 0) {
log.debug("Try with removed quotes in Content-Type charset.");
const contentTypeField = msg.headerFields.get("content-type")[0];
const sanitizedContentTypeField = contentTypeField.replace(/charset="([^"]+)"/i, "charset=$1");

if (contentTypeField !== sanitizedContentTypeField) {
msg.headerFields.get("content-type")[0] = sanitizedContentTypeField;
// Compute the input for the header hash
headerHashInput = computeHeaderHashInput(msg,DKIMSignature);
log.debug("Header hash input:\n" + headerHashInput);
// verify Signature
keyInfo = {};
isValid = verifyFunction(DKIMSignature.DKIMKey.p, headerHashInput,
DKIMSignature.a_hash, DKIMSignature.b, DKIMSignature.warnings, keyInfo);

if (!isValid) {
throw new DKIM_SigError("DKIM_SIGERROR_BADSIG");
} else if (prefs.getIntPref("error.contentTypeCharsetAddedQuotes.treatAs") === 1) {
if (prefs.getIntPref("error.contentTypeCharsetAddedQuotes.treatAs") === 1) {
DKIMSignature.warnings.push({name: "DKIM_SIGERROR_CONTENT_TYPE_CHARSET_ADDED_QUOTES"});
log.debug("Warning: DKIM_SIGERROR_CONTENT_TYPE_CHARSET_ADDED_QUOTES");
}
} else {
throw new DKIM_SigError("DKIM_SIGERROR_BADSIG");
log.debug("Nothing changed, no need to reverify...");
}
}
if (!isValid && prefs.getBoolPref("error.sanitizeSubject")) {
log.debug("Trying to sanitize the subject header field");
const subjectField = msg.headerFields.get("subject")[0];
const sanitizeRegexp = /(Subject:\s)(?:\*|\[).+(?:\*|\])\s(.*)/;
const sanitizedSubject = subjectField.replace(sanitizeRegexp, "$2").trim();
const sanitizedSubjectField = subjectField.replace(sanitizeRegexp, "$1$2");

if (subjectField !== sanitizedSubjectField) {
msg.headerFields.get("subject")[0] = sanitizedSubjectField;
// Compute the input for the header hash
headerHashInput = computeHeaderHashInput(msg,DKIMSignature);
log.debug("Header hash input:\n" + headerHashInput);
// verify Signature
keyInfo = {};
isValid = verifyFunction(DKIMSignature.DKIMKey.p, headerHashInput,
DKIMSignature.a_hash, DKIMSignature.b, DKIMSignature.warnings, keyInfo);
if (isValid) {
// Adding a warning, that the subject was changed
DKIMSignature.warnings.push({ name: "DKIM_SIGERROR_SUBJECT_MODIFIED", params: [sanitizedSubject] });
log.debug("Sanitized subject: " + sanitizedSubject);
} else {
// Restoring the original subject field
msg.headerFields.get("subject")[0] = subjectField;
}
} else {
log.debug("Nothing changed, no need to reverify...");
}
}

if (!isValid) {
throw new DKIM_SigError("DKIM_SIGERROR_BADSIG");
}

if (DKIMSignature.a_sig !== DKIMSignature.DKIMKey.k) {
throw new DKIM_SigError("DKIM_SIGERROR_KEY_MISMATCHED_K");
}
Expand Down