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

core(is-on-https): add mixed-content resolution #10975

Merged
merged 23 commits into from
Jul 10, 2020
Merged

Conversation

connorjclark
Copy link
Collaborator

node lighthouse-cli https://very.badssl.com/ --view

image

The mixed-content Issue won't be emitted until M84 (next month), so this new column is added as a progressive enhancement.

@connorjclark connorjclark requested a review from a team as a code owner June 16, 2020 18:12
@connorjclark connorjclark requested review from paulirish and removed request for a team June 16, 2020 18:12
lighthouse-core/audits/is-on-https.js Outdated Show resolved Hide resolved
}
"score": null,
"scoreDisplayMode": "error",
"errorMessage": "Required InspectorIssues gatherer did not run."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm

should we use optionalArtifacts again?
seems good.

but also we can add a stub to the artifacts fixtures

Copy link
Collaborator Author

@connorjclark connorjclark Jun 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'll just fix the sample artifacts.

don't think optional artifacts fits here. it's meant to allow flexibility in which gatherers can run today, based only on what gatherers are in the config. since InspectorIssues is in the default config, it won't benefit.

/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
{key: 'url', itemType: 'url', text: str_(UIStrings.columnInsecureURL)},
];

// Mixed-content issues aren't emitted until M84.
if (artifacts.InspectorIssues.mixedContent.length) {
headings.push(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so does anyone hate this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so does anyone hate this

seems fine for < m84, but it is a little weird after that to have an optional column.

I assume if there are items caught by the HTTPS.isSecureRecord filter, they should (almost?) always have a mixed Content issue associated with them. Would it be terrible to give every entry a default resolution: undefined then, since they'll (almost?) always have one anyways ≥ m84?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my expectation.

Also, I'll file an issue to follow up and remove the isSecureRecord part completely once M84 lands.

Would it be terrible to give every entry a default resolution: undefined then

sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'll file an issue to follow up and remove the isSecureRecord part completely make the header always added once M84 lands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc #10976 some other m84 stuff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump on

I'll file an issue to follow up and make the header always added once M84 lands.

so it's not lost in the middle of this review.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
{key: 'url', itemType: 'url', text: str_(UIStrings.columnInsecureURL)},
];

// Mixed-content issues aren't emitted until M84.
if (artifacts.InspectorIssues.mixedContent.length) {
headings.push(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so does anyone hate this

seems fine for < m84, but it is a little weird after that to have an optional column.

I assume if there are items caught by the HTTPS.isSecureRecord filter, they should (almost?) always have a mixed Content issue associated with them. Would it be terrible to give every entry a default resolution: undefined then, since they'll (almost?) always have one anyways ≥ m84?

lighthouse-core/audits/is-on-https.js Show resolved Hide resolved
@@ -42,6 +43,7 @@ describe('Security: HTTPS audit', () => {
assert.strictEqual(result.score, 0);
expect(result.displayValue).toBeDisplayString('1 insecure request found');
assert.deepEqual(result.extendedInfo.value[0], {url: 'http://insecure.com/image.jpeg'});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.extendedInfo

guh we really have to land #10779 :)

lighthouse-core/audits/is-on-https.js Show resolved Hide resolved
lighthouse-core/audits/is-on-https.js Outdated Show resolved Hide resolved
Comment on lines 73 to 74
expect(result.details.items[0]).toMatchObject({url: 'http://localhost/image.jpeg'});
expect(result.details.items[0].resolution).toBeDisplayString('Blocked');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit: can be fancy and do

Suggested change
expect(result.details.items[0]).toMatchObject({url: 'http://localhost/image.jpeg'});
expect(result.details.items[0].resolution).toBeDisplayString('Blocked');
expect(result.details.items[0]).toMatchObject({
url: 'http://localhost/image.jpeg',
resolution: expect.toBeDisplayString('Blocked'),
});

(or it could be s/toMatchObject/toEqual if both are there?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i missed the fancy

neat

@brendankenny
Copy link
Member

oh, https://web.dev/is-on-https needs updating as well. Maybe there are devtools docs we can utilize for the resolution types?

cc @kaycebasques

@connorjclark
Copy link
Collaborator Author

connorjclark commented Jun 19, 2020

image

the http jquery script doesn't emit a mixed-content issue ... I guess because the domain is localhost so it's not considered insecure.

This audit currently checks if the resource is on secure domain, but shouldn't we check if the finalURL is? if on localhost shouldn't this audit always pass?

@brendankenny
Copy link
Member

This audit currently checks if the resource is on secure domain, but shouldn't we check if the finalURL is? so if on localhost, this audit always passes?

good question. It's possible this is intentional (you don't get penalized for loading resources from localhost because what can you do about that during local development, but you do get penalized developing in localhost but loading resources that will be insecure once you deploy your site into production), but I don't remember. @paulirish @patrickhulce?

If it is intentional we should make sure to write it down this time :)

@patrickhulce
Copy link
Collaborator

This audit currently checks if the resource is on secure domain, but shouldn't we check if the finalURL is? if on localhost shouldn't this audit always pass?

It's possible this is intentional (you don't get penalized for loading resources from localhost because what can you do about that during local development, but you do get penalized developing in localhost but loading resources that will be insecure once you deploy your site into production)

I don't understand these questions and I'm not sure what we would document being intentional so I'm guessing that things I thought were unambiguous about this audit aren't actually shared by anyone else 😆

I always thought that the is-on-https audit is about flagging requests the navigation is causing that aren't made to a secure origin. With that lens, it immediately follows that http://localhost shouldn't be flagged because they're made to a secure origin while any requests to a http://example.com are obviously not made to a secure origin just because they're requested by a page that's on localhost. Does that answer the questions above or am I still missing something?

@brendankenny
Copy link
Member

Does that answer the questions above or am I still missing something?

No, I think that's it :) It does fall out as a natural consequence when thought about it that way, I guess it's just coming up now because the MixedContentIssues don't think that it's an issue.

@connorjclark
Copy link
Collaborator Author

Ok, thanks for framing the audit patrick. I think the issue was the assumption that mixed content issues would 1:1 replace this audit. That is clearly not the case.

So we now know that there are items we want to surface that wont have a mixed content issue. For resolution, let's just put allowed or something? I think we'll only have this edge case for localhost.

/** Label for a column in a data table; entries in the column will be how the browser handled insecure (non-HTTPS) network requests. */
columnResolution: 'Resolution',
/** Value for the resolution column in a data table; denotes that the insecure URL was allowed by the browser. */
allowed: 'Allowed',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording wise its odd that the first column is "URL" and second column is "Resolution"
The resolution doesn't apply to that URL, but to the network request of that URL.

Adding "request" here I think helps both this and brendan's concern.

"Request allowed/blocked" ? "Request allowed with warning"?

btw here's an example of a warning case (insecure form submission): https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/loader/mixed_content_checker.cc;l=731-747;drc=5ba77dad98cf94506cf3700f9e12fcdc65fadfb6

"Request automatically upgraded to HTTPS"

/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
{key: 'url', itemType: 'url', text: str_(UIStrings.columnInsecureURL)},
];

// Mixed-content issues aren't emitted until M84.
if (artifacts.InspectorIssues.mixedContent.length) {
headings.push(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc #10976 some other m84 stuff.

@@ -33,7 +33,9 @@ class InspectorIssues extends Gatherer {
async beforePass(passContext) {
const driver = passContext.driver;
driver.on('Audits.issueAdded', this._onIssueAdded);
// try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove these all now tho?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It breaks appveyor rn :/
image

but yeah once #10976 lands we can set a min chrome for the is-on-https expectation.

await driver.sendCommand('Audits.enable');
try {
await driver.sendCommand('Audits.enable');
} catch (_) {} // Fails if Chrome is old.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Fails if Chrome is older than mXX"

not a huge deal but my brain associates "old"/age with higher numbers, but here, older means lower. 😖

maybe we just stick to if Chrome is < m82 or w/e

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(marking)

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

maybe add a smoke test entry? dbw has a "resolution": "Allowed" for its 1 item

/** Label for a column in a data table; entries in the column will be how the browser handled insecure (non-HTTPS) network requests. */
columnResolution: 'Resolution',
/** Value for the resolution column in a data table; denotes that the insecure URL was allowed by the browser. */
allowed: 'Allowed',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think Request Resolution: 'Allowed' still raises "why is Lighthouse marking it as a problem if it was allowed?" but it seems fine to wait to see if there's any actual user confusion before coming up with something new :)

I only raise it because if it does come up in the future, I don't want to see us saying "oh, well it should just be allowed and not marked as a failure, then" and instead keep following @patrickhulce's reasoning in #10975 (comment).

/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
{key: 'url', itemType: 'url', text: str_(UIStrings.columnInsecureURL)},
];

// Mixed-content issues aren't emitted until M84.
if (artifacts.InspectorIssues.mixedContent.length) {
headings.push(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump on

I'll file an issue to follow up and make the header always added once M84 lands.

so it's not lost in the middle of this review.

// (localhost is a secure context), but we still identify `http` requests
// as an "Allowed" insecure URL.
for (const item of items) {
if (!item.resolution) item.resolution = UIStrings.allowed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!item.resolution) item.resolution = UIStrings.allowed;
if (!item.resolution) item.resolution = str_(UIStrings.allowed);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bahhhhh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants