Skip to content

Instantly share code, notes, and snippets.

@makyo
Last active October 23, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makyo/1e07a1065b2366e695df8ca5bc0b54d8 to your computer and use it in GitHub Desktop.
Save makyo/1e07a1065b2366e695df8ca5bc0b54d8 to your computer and use it in GitHub Desktop.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
autoindex on;
location / {
try_files $uri $uri/ =404;
}
location /widget-embed {
alias /var/www/html;
}
location /widget-noembed {
add_header X-Frame-Options DENY;
alias /var/www/html;
}
location /widget-redirect-noembed {
return 301 $scheme://$host/widget-noembed;
}
location /widget-redirect-missing {
return 301 $scheme://$host/bad-wolf;
}
location /widget-redirect-noembed-reverse {
add_header X-Frame-Options DENY;
return 301 $scheme://$host/widget-embed;
}
}
package main
import (
"fmt"
"net/http"
)
func test(url string) {
r, err := http.Head(url)
fmt.Printf("res: %+v; err: %+v\n\n", r, err)
}
func main() {
test("http://synapse.local/widget-embed")
test("http://synapse.local/widget-noembed")
test("http://synapse.local/widget-redirect-embed")
test("http://synapse.local/widget-redirect-noembed")
test("http://synapse.local/widget-redirect-noembed-reverse")
}
// Allows embed, no DENY
res: &{Status:200 OK StatusCode:200 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept-Ranges:[bytes] Connection:[keep-alive] Content-Length:[612] Content-Type:[text/html] Date:[Wed, 23 Oct 2019 14:35:23 GMT] Etag:["5db05eaf-264"] Last-Modified:[Wed, 23 Oct 2019 14:07:43 GMT] Server:[nginx/1.15.9 (Ubuntu)]] Body:{} ContentLength:612 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0xc0000c8100 TLS:<nil>}; err: <nil>
// Does not allow embed, has DENY
res: &{Status:200 OK StatusCode:200 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept-Ranges:[bytes] Connection:[keep-alive] Content-Length:[612] Content-Type:[text/html] Date:[Wed, 23 Oct 2019 14:35:23 GMT] Etag:["5db05eaf-264"] Last-Modified:[Wed, 23 Oct 2019 14:07:43 GMT] Server:[nginx/1.15.9 (Ubuntu)] X-Frame-Options:[DENY]] Body:{} ContentLength:612 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0xc000114100 TLS:<nil>}; err: <nil>
// Allows embed, redirects to allow embed, allows embed, no DENY
res: &{Status:404 Not Found StatusCode:404 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Connection:[keep-alive] Content-Length:[162] Content-Type:[text/html] Date:[Wed, 23 Oct 2019 14:35:23 GMT] Server:[nginx/1.15.9 (Ubuntu)]] Body:{} ContentLength:162 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0xc00014c000 TLS:<nil>}; err: <nil>
// Allows embed, redirects to disallow embed, does not allow embed, has DENY
res: &{Status:200 OK StatusCode:200 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept-Ranges:[bytes] Connection:[keep-alive] Content-Length:[612] Content-Type:[text/html] Date:[Wed, 23 Oct 2019 14:35:23 GMT] Etag:["5db05eaf-264"] Last-Modified:[Wed, 23 Oct 2019 14:07:43 GMT] Server:[nginx/1.15.9 (Ubuntu)] X-Frame-Options:[DENY]] Body:{} ContentLength:612 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0xc00014c100 TLS:<nil>}; err: <nil>
// Disallows embed, redirects to allow embed, allows embed, no DENY
res: &{Status:200 OK StatusCode:200 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept-Ranges:[bytes] Connection:[keep-alive] Content-Length:[612] Content-Type:[text/html] Date:[Wed, 23 Oct 2019 14:35:23 GMT] Etag:["5db05eaf-264"] Last-Modified:[Wed, 23 Oct 2019 14:07:43 GMT] Server:[nginx/1.15.9 (Ubuntu)]] Body:{} ContentLength:612 TransferEncoding:[] Close:false Uncompressed:false Trailer:map[] Request:0xc0000c8600 TLS:<nil>}; err: <nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment