Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline CORS headers #52

Merged
merged 1 commit into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/vhost-gen
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ if os.environ.get("MYPY_CHECK", False):
# --------------------------------------------------------------------------------------------------
APPNAME = "vhost-gen"
APPREPO = "https://github.com/devilbox/vhost-gen"
VERSION = "1.0.9"
RELDATE = "2022-12-27"
VERSION = "1.0.10"
RELDATE = "2022-12-31"

# Default paths
CONFIG_PATH = "/etc/vhost-gen/conf.yml"
Expand Down
9 changes: 6 additions & 3 deletions etc/templates/apache22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,16 @@ features:
Allow from all
</Location>

# https://stackoverflow.com/a/42558499
# https://fetch.spec.whatwg.org/#forbidden-header-name
xdomain_request: |
# Allow cross domain request from these hosts
SetEnvIf Origin "__REGEX__" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods "HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "Accept, Authorization, Content-Security-Policy, Content-Type, Location, Origin, X-Requested-With"
Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
Header always set Access-Control-Max-Age "0"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
Expand Down
9 changes: 6 additions & 3 deletions etc/templates/apache24.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,16 @@ features:
Require all granted
</Location>

# https://stackoverflow.com/a/42558499
# https://fetch.spec.whatwg.org/#forbidden-header-name
xdomain_request: |
# Allow cross domain request from these hosts
SetEnvIf Origin "__REGEX__" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header always set Access-Control-Allow-Methods "HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "Accept, Authorization, Content-Security-Policy, Content-Type, Location, Origin, X-Requested-With"
Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"
Header always set Access-Control-Max-Age "0"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
Expand Down
9 changes: 5 additions & 4 deletions etc/templates/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ features:

xdomain_request: |
# Allow cross domain request from these hosts
# https://fetch.spec.whatwg.org/#forbidden-header-name
if ( $http_origin ~* (__REGEX__) ) {
add_header "Access-Control-Allow-Origin" "$http_origin";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header "Access-Control-Allow-Origin" "$http_origin";
add_header 'Access-Control-Allow-Methods' 'HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Accept, Authorization, Content-Security-Policy, Content-Type, Location, Origin, X-Requested-With';
add_header 'Access-Control-Expose-Headers' 'Content-Security-Policy, Location';
add_header 'Access-Control-Max-Age' 0;
return 200;
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="vhost-gen",
version="1.0.9",
version="1.0.10",
description="Configurable vHost generator for Apache 2.2, Apache 2.4 and Nginx.",
license="MIT",
long_description=long_description,
Expand Down