@hint/hint-no-protocol-relative-urls
hint that that checks if protocol relative URLs are used
Last updated 2 years ago by vidorteg .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @hint/hint-no-protocol-relative-urls 
SYNC missed versions from official npm registry.

No protocol-relative URLs (no-protocol-relative-urls)

no-protocol-relative-urls warns against using scheme-relative URLs (commonly known as protocol-relative URLs).

Why is this important?

A shorthand way of specifying URLs is to remove the protocol and let the browser determine the relative protocol based on the current connection to the resource.

As the web moves towards HTTPS everywhere, the use of protocol-relative URLs has become an anti-pattern, exposing some sites to man in the middle compromises and is therefore best avoided.

Particularly for web sites/apps served over HTTP, other drawbacks when using protocol relative URLs include:

  • Performance

    • If the web site/app is served over HTTP, for every protocol-relative URL that does support HTTPS and:

      • does a redirect to it (i.e. most CDNs), the load time will take longer than if the request was made directly to the https:// version of the URL.

      • does not redirect to it, you may be missing out on things such as Brotli compression and HTTP/2 that are only supported by browsers over HTTPS.

  • Security

    If protocol-relative URLs are used for CDN links, their domain is not in the browser’s HSTS preload list, and the first request is not made over HTTP, there is a high risk of man-in-the-middle attacks.

    Of course, if the web site/app is served over HTTP it is already exposed to those types of attacks, but in general CDNs constitute a high-value target, and therefore, are much more likely to be attacked than most of the individual sites that use them.

What does the hint check?

The hint checks for protocol-relative URLs.

Note: Currently the hint does not check for protocol-relative URLs inside of stylesheets and scripts.

Let’s presume example1.com does not support HTTPS and example2.com does.

Examples that trigger the hint

<link rel="stylesheet" href="//example1.com/style.css">
<script src="//example2.com/script.js"></script>

Examples that pass the hint

<link rel="stylesheet" href="http://example1.com/style.css">
<script src="https://example2.com/script.js"></script>

How to use this hint?

This package is installed automatically by webhint:

npm install hint --save-dev

To use it, activate it via the .hintrc configuration file:

{
    "connector": {...},
    "formatters": [...],
    "hints": {
        "no-protocol-relative-urls": "error",
        ...
    },
    "parsers": [...],
    ...
}

Note: The recommended way of running webhint is as a devDependency of your project.

Further Reading

Current Tags

  • 3.1.7                                ...           latest (2 years ago)

53 Versions

  • 3.1.7                                ...           2 years ago
  • 3.1.6                                ...           3 years ago
  • 3.1.5                                ...           3 years ago
  • 3.1.4                                ...           4 years ago
  • 3.1.3                                ...           4 years ago
  • 3.1.2                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.15                                ...           4 years ago
  • 3.0.14                                ...           4 years ago
  • 3.0.13                                ...           5 years ago
  • 3.0.12                                ...           5 years ago
  • 3.0.11                                ...           5 years ago
  • 3.0.10                                ...           5 years ago
  • 3.0.9                                ...           5 years ago
  • 3.0.8                                ...           5 years ago
  • 3.0.7                                ...           5 years ago
  • 3.0.6                                ...           5 years ago
  • 3.0.5                                ...           6 years ago
  • 3.0.4                                ...           6 years ago
  • 3.0.3                                ...           6 years ago
  • 3.0.2                                ...           6 years ago
  • 3.0.1                                ...           6 years ago
  • 3.0.0                                ...           7 years ago
  • 2.4.3                                ...           7 years ago
  • 2.4.2                                ...           7 years ago
  • 2.4.1                                ...           7 years ago
  • 2.4.0                                ...           7 years ago
  • 2.3.11                                ...           7 years ago
  • 2.3.10                                ...           7 years ago
  • 2.3.9                                ...           7 years ago
  • 2.3.8                                ...           7 years ago
  • 2.3.7                                ...           7 years ago
  • 2.3.6                                ...           7 years ago
  • 2.3.5                                ...           7 years ago
  • 2.3.4                                ...           7 years ago
  • 2.3.3                                ...           7 years ago
  • 2.3.2                                ...           7 years ago
  • 2.3.1                                ...           7 years ago
  • 2.3.0                                ...           7 years ago
  • 2.2.2                                ...           8 years ago
  • 2.2.1                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.2                                ...           8 years ago
  • 2.1.1                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.0.4                                ...           8 years ago
  • 1.0.3                                ...           8 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 1.0.0-beta.0                                ...           8 years ago
Downloads
Total 92
Today 0
This Week 1
This Month 73
Last Day 0
Last Week 14
Last Month 19
Dependencies (5)
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE