momocow / webpack-userscript

A Webpack plugin for userscript projects. 🙈
https://cow.moe/webpack-userscript/
MIT License
200 stars 21 forks source link

@resource don't support SSRI #49

Closed yingziwu closed 3 years ago

yingziwu commented 3 years ago

According to the documentation, the @resource should be look like follows:

// @resource icon1 http://www.tampermonkey.net/favicon.ico
// @resource icon2 /images/icon.png
// @resource html http://www.tampermonkey.net/index.html
// @resource xml http://www.tampermonkey.net/crx/tampermonkey.xml
// @resource SRIsecured1 http://www.tampermonkey.net/favicon.ico#md5=123434...
// @resource SRIsecured2 http://www.tampermonkey.net/favicon.ico#md5=123434...;sha256=234234...

But after enable SSRI and the @resource get TypeError [ERR_INVALID_URL].

TypeError [ERR_INVALID_URL]: Invalid URL: icon https://www.tampermonkey.net/favicon.ico
    at new NodeError (node:internal/errors:329:5)
    at onParseError (node:internal/url:537:9)
    at new URL (node:internal/url:613:5)
    at module.exports.computeSSRI (/srv/app/webpack-userscript/lib/ssri.js:26:18)
    at /srv/app/webpack-userscript/lib/index.js:184:43
    at Array.map (<anonymous>)
    at /srv/app/webpack-userscript/lib/index.js:181:18
    at processTicksAndRejections (node:internal/process/task_queues:94:5) 

webpack.config.js

const path = require('path')
const WebpackUserscript = require('../../..')

const DIST_DIR = path.resolve(__dirname, 'dist')

module.exports = {
  context: __dirname,
  mode: 'production',
  entry: path.join(__dirname, 'index.js'),
  output: {
    path: DIST_DIR,
    filename: 'index.user.js'
  },
  plugins: [
    new WebpackUserscript({
      headers: path.resolve(__dirname, 'header.json'),
      ssri: true
    })
  ]
}

header.json

{
  "name": "@webpack-tampermonkey-bug",
  "require": [
    "https://cdn.jsdelivr.net/npm/file-saver@2.0.5/dist/FileSaver.min.js",
    "https://cdn.jsdelivr.net/npm/jszip@3.6.0/dist/jszip.min.js",
    "https://cdn.jsdelivr.net/npm/crypto-js@4.0.0/crypto-js.min.js"
  ],
  "antifeature": "tracking We have some sort of analytics included",
  "resource": [
    "icon https://www.tampermonkey.net/favicon.ico",
    "html https://www.tampermonkey.net/index.html"
  ]
}
inazuma-bot commented 3 years ago

:tada: This issue has been resolved in version 2.5.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket: