commit f04a8c37363d9a40c933d7f9d1f82fc398257c40
parent 4bbae6e17a8b93d0f079ed22025c595d5838be06
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 11 Feb 2018 01:03:56 -0500
Fix "channel is undefined" for invalid HTTP response during WebDAV sync
Follow-up to 4bbae6e17
We're now using Zotero.HTTP.request(), which does its own checking for
security errors, so there's no need to do WebDAV-specific checks (though
we could consider checking for Zotero.HTTP.SecurityError and showing
more specific messages, since a self-signed certificate is more likely
in the case of WebDAV).
Diffstat:
1 file changed, 15 insertions(+), 107 deletions(-)
diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js
@@ -224,7 +224,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
try {
var req = yield Zotero.HTTP.request("OPTIONS", this.rootURI);
- this._checkResponse(req);
Zotero.debug("WebDAV credentials cached");
this._cachedCredentials = true;
@@ -595,30 +594,22 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
}
// Test whether URL is WebDAV-enabled
- try {
- var req = yield Zotero.HTTP.request(
- "OPTIONS",
- uri,
- {
- successCodes: [200, 404],
- requestObserver: function (req) {
- if (req.channel) {
- channel = req.channel;
- }
- if (options.onRequest) {
- options.onRequest(req);
- }
- },
- debug: true
- }
- );
- }
- catch (e) {
- if (e instanceof Zotero.HTTP.UnexpectedStatusException) {
- this._checkResponse(e.xmlhttp, e.channel);
+ var req = yield Zotero.HTTP.request(
+ "OPTIONS",
+ uri,
+ {
+ successCodes: [200, 404],
+ requestObserver: function (req) {
+ if (req.channel) {
+ channel = req.channel;
+ }
+ if (options.onRequest) {
+ options.onRequest(req);
+ }
+ },
+ debug: true
}
- throw e;
- }
+ );
Zotero.debug(req.getAllResponseHeaders());
@@ -1133,8 +1124,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
throw e;
}
- this._checkResponse(req);
-
// mod_speling can return 300s for 404s with base name matches
if (req.status == 404 || req.status == 300) {
return false;
@@ -1469,87 +1458,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
}),
- /**
- * Checks for an invalid SSL certificate and throws a nice error
- */
- _checkResponse: function (req, channel) {
- if (req.status != 0) return;
-
- // Check if the error we encountered is really an SSL error
- // Logic borrowed from https://developer.mozilla.org/en-US/docs/How_to_check_the_security_state_of_an_XMLHTTPRequest_over_SSL
- // http://mxr.mozilla.org/mozilla-central/source/security/nss/lib/ssl/sslerr.h
- // http://mxr.mozilla.org/mozilla-central/source/security/nss/lib/util/secerr.h
- var secErrLimit = Ci.nsINSSErrorsService.NSS_SEC_ERROR_LIMIT - Ci.nsINSSErrorsService.NSS_SEC_ERROR_BASE;
- var secErr = Math.abs(Ci.nsINSSErrorsService.NSS_SEC_ERROR_BASE) - (channel.status & 0xffff);
- var sslErrLimit = Ci.nsINSSErrorsService.NSS_SSL_ERROR_LIMIT - Ci.nsINSSErrorsService.NSS_SSL_ERROR_BASE;
- var sslErr = Math.abs(Ci.nsINSSErrorsService.NSS_SSL_ERROR_BASE) - (channel.status & 0xffff);
- if( (secErr < 0 || secErr > secErrLimit) && (sslErr < 0 || sslErr > sslErrLimit) ) {
- return;
- }
-
- var secInfo = channel.securityInfo;
- if (secInfo instanceof Ci.nsITransportSecurityInfo) {
- secInfo.QueryInterface(Ci.nsITransportSecurityInfo);
- if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_INSECURE) == Ci.nsIWebProgressListener.STATE_IS_INSECURE) {
- var host = 'host';
- try {
- host = channel.URI.host;
- }
- catch (e) {
- Zotero.debug(e);
- }
-
- var msg = Zotero.getString('sync.storage.error.webdav.sslCertificateError', host);
- // In Standalone, provide cert_override.txt instructions and a
- // button to open the Zotero profile directory
- if (Zotero.isStandalone) {
- msg += "\n\n" + Zotero.getString('sync.storage.error.webdav.seeCertOverrideDocumentation');
- var buttonText = Zotero.getString('general.openDocumentation');
- var func = function () {
- var zp = Zotero.getActiveZoteroPane();
- zp.loadURI("https://www.zotero.org/support/kb/cert_override", { shiftKey: true });
- };
- }
- // In Firefox display a button to load the WebDAV URL
- else {
- msg += "\n\n" + Zotero.getString('sync.storage.error.webdav.loadURLForMoreInfo');
- var buttonText = Zotero.getString('sync.storage.error.webdav.loadURL');
- var func = function () {
- var zp = Zotero.getActiveZoteroPane();
- zp.loadURI(channel.URI.spec, { shiftKey: true });
- };
- }
-
- var e = new Zotero.Error(
- msg,
- 0,
- {
- dialogButtonText: buttonText,
- dialogButtonCallback: func
- }
- );
- throw e;
- }
- else if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_BROKEN) == Ci.nsIWebProgressListener.STATE_IS_BROKEN) {
- var msg = Zotero.getString('sync.storage.error.webdav.sslConnectionError', host) +
- Zotero.getString('sync.storage.error.webdav.loadURLForMoreInfo');
- var e = new Zotero.Error(
- msg,
- 0,
- {
- dialogButtonText: Zotero.getString('sync.storage.error.webdav.loadURL'),
- dialogButtonCallback: function () {
- var zp = Zotero.getActiveZoteroPane();
- zp.loadURI(channel.URI.spec, { shiftKey: true });
- }
- }
- );
- throw e;
- }
- }
- },
-
-
_throwFriendlyError: function (method, url, status) {
throw new Error(
Zotero.getString('sync.storage.error.webdav.requestError', [status, method])