Skip to content

Fixes #2409. Don't pre-fill forms for "self reports" (webcompat.com) #2439

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

Merged
merged 3 commits into from
Jun 6, 2018
Merged
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
40 changes: 32 additions & 8 deletions webcompat/static/js/lib/bugform.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function BugForm() {
this.submitButtons = $("#js-ReportForm .js-Button");
this.submitTypeInput = $("#submit_type:hidden");
this.uploadLabel = $(".js-label-upload");
this.urlParamRegExp = /url=([^&]+)/;

this.UPLOAD_LIMIT = 1024 * 1024 * 4;

Expand Down Expand Up @@ -88,7 +89,12 @@ function BugForm() {
this.onReceiveMessage = this.onReceiveMessage.bind(this);
this.preventSubmitByEnter = this.preventSubmitByEnter.bind(this);

this.checkParams();
// Make sure we're not getting a report
// about our own site before checking params.
if (!this.isSelfReport()) {
this.checkParams();
}

this.disableSubmits();
this.initAutogrowFields();
this.urlField.on("blur input", this.checkURLValidity);
Expand Down Expand Up @@ -160,7 +166,12 @@ function BugForm() {
};

this.onReceiveMessage = function(event) {
// Make sure the data is coming from ~*inside the house*~!
// We're getting a report about our own site, so let's bail.
if (this.isSelfReport()) {
return false;
}

// Make sure the data is coming from a trusted source.
// (i.e., our add-on or some other priviledged code sent it)
if (location.origin === event.origin) {
// See https://github.com/webcompat/webcompat.com/issues/1252 to track
Expand Down Expand Up @@ -226,18 +237,29 @@ function BugForm() {
img.src = dataURI;
};

// Is the user trying to report a site against webcompat.com itself?
this.isSelfReport = function(href) {
href = href || location.href;
var url = href.match(this.urlParamRegExp);
if (url !== null) {
if (_.includes(decodeURIComponent(url[0]), location.origin)) {
return true;
}
}
return false;
};

// Do some extra work based on the GET params that come with the request
this.checkParams = function() {
// Don't bother doing any work for bare requests.
if (!location.search) {
return;
}

var urlParam = location.href.match(/url=([^&]*)/);
if (urlParam !== null) {
// weird Gecko bug. See https://bugzilla.mozilla.org/show_bug.cgi?id=1098037
urlParam = this.trimWyciwyg(urlParam[1]);
this.urlField.val(decodeURIComponent(urlParam));
var url = location.href.match(this.urlParamRegExp);
if (url !== null) {
url = this.trimWyciwyg(decodeURIComponent(url[1]));
this.urlField.val(url);
this.makeValid("url");
}

Expand Down Expand Up @@ -271,7 +293,9 @@ function BugForm() {
};

this.trimWyciwyg = function(url) {
//trim wyciwyg://N/ from URL.
// Trim wyciwyg://N/ from URL, if found.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1098037 &
// https://en.wikipedia.org/wiki/WYCIWYG
var wyciwygRe = /(wyciwyg:\/\/\d+\/)/i;
if (url.search(wyciwygRe) !== 0) {
return url;
Expand Down