sourcemap-searcher

网站sourcemap文件泄露检测器

  1. // ==UserScript==
  2. // @name sourcemap-searcher
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 网站sourcemap文件泄露检测器
  6. // @author wuuconix
  7. // @include *
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=wuuconix.link
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. var judge = (url, protocol, origin, href) => {
  14. if (url.startsWith("//")) { //省略协议的写法
  15. url = `${protocol}${url}`
  16. } else if (url.startsWith("/")) { //文件位于网站根目录
  17. url = `${origin}${url}`
  18. } else if (url.startsWith("./")) { //使用相对路径
  19. url = href.slice(0, href.lastIndexOf("/")) + url.slice(1)
  20. } else if (!url.startsWith("http")) { //相对路径的js文件加上origin 构造完整url
  21. url = href.slice(0, href.lastIndexOf("/")) + "/" + url
  22. }
  23. if (url.includes("?")) { //针对那些后面有query的文件 比如index.js?max_age=31536000
  24. url = url.slice(0, url.indexOf("?"))
  25. }
  26. if ((url.endsWith(".js") && !url.endsWith(".min.js")) || (url.endsWith(".css") && !url.endsWith(".min.css"))) { //加上.map构造出sourcemap文件路径
  27. url = `${url}.map`
  28. console.log(url)
  29. fetch(url).then(res => {
  30. if (res.status == 200) {
  31. console.log(`------bingo------\n${url} 疑似存在sourcemap文件泄露\n`)
  32. }
  33. }).catch(e => {
  34. console.log(`fetch ${url} 失败: ${e}`)
  35. })
  36. }
  37. }
  38.  
  39. var sms = () => {
  40. const scripts = document.querySelectorAll("script")
  41. const links = document.querySelectorAll("link")
  42. const { protocol, origin, href } = window.location //包含协议和域名
  43. for (let { src } of scripts) {
  44. judge(src, protocol, origin, href)
  45. }
  46. for (let { href: src } of links) {
  47. judge(src, protocol, origin, href)
  48. }
  49. }
  50.  
  51. window.sms = sms

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址