|
23 | 23 | "/": { |
24 | 24 | "tools.staticdir.on": True, |
25 | 25 | "tools.sessions.on": True, |
26 | | - "tools.sessions.secure" = True, |
27 | | - "tools.sessions.httponly" = True, |
28 | | - "tools.secureheaders.on" = True, |
29 | | - "tools.staticdir.dir": os.path.join( |
30 | | - os.path.dirname(os.path.abspath(__file__)), "ui" |
31 | | - ), |
| 26 | + "tools.sessions.secure": True, |
| 27 | + "tools.sessions.httponly": True, |
| 28 | + "tools.secureheaders.on": True, |
| 29 | + "tools.staticdir.dir": os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui"), |
32 | 30 | }, |
33 | 31 | } |
34 | 32 |
|
35 | 33 |
|
| 34 | +def secureheaders(): |
| 35 | + headers = cherrypy.response.headers |
| 36 | + headers["X-Frame-Options"] = "DENY" |
| 37 | + headers["X-XSS-Protection"] = "1; mode=block" |
| 38 | + headers["Content-Security-Policy"] = "default-src='self'" |
| 39 | + |
| 40 | + |
36 | 41 | def is_valid_admin_login(username, password): |
37 | 42 | if USERS is None: |
38 | 43 | return True |
@@ -162,24 +167,12 @@ def get_args(): |
162 | 167 | parser.add_argument("--gluster-binary", default="gluster") |
163 | 168 | parser.add_argument( |
164 | 169 | "--auth-file", |
165 | | - help=( |
166 | | - "Users Credentials file. One user entry per row " |
167 | | - "in the format <username>=<password_hash>" |
168 | | - ), |
169 | | - ) |
170 | | - parser.add_argument( |
171 | | - "--ssl-cert", default=None, help=("Path to SSL Certificate used by Gdash") |
| 170 | + help=("Users Credentials file. One user entry per row " "in the format <username>=<password_hash>"), |
172 | 171 | ) |
173 | | - parser.add_argument( |
174 | | - "--ssl-key", default=None, help=("Path to SSL Key used by Gdash") |
175 | | - ) |
176 | | - parser.add_argument( |
177 | | - "--ssl-ca", default=None, help=("Path to SSL CA Certificate used by Gdash") |
178 | | - ) |
179 | | - parser.add_argument( |
180 | | - "--ssl-ciphers", default=None, help=("List of SSL Ciphers to allow") |
181 | | - ) |
182 | | - |
| 172 | + parser.add_argument("--ssl-cert", default=None, help=("Path to SSL Certificate used by Gdash")) |
| 173 | + parser.add_argument("--ssl-key", default=None, help=("Path to SSL Key used by Gdash")) |
| 174 | + parser.add_argument("--ssl-ca", default=None, help=("Path to SSL CA Certificate used by Gdash")) |
| 175 | + parser.add_argument("--ssl-ciphers", default=None, help=("List of SSL Ciphers to allow")) |
183 | 176 | return parser.parse_args() |
184 | 177 |
|
185 | 178 |
|
@@ -217,6 +210,7 @@ def main(): |
217 | 210 | cherrypy_cfg["server.ssl_module"] = "builtin" |
218 | 211 |
|
219 | 212 | cherrypy.config.update(cherrypy_cfg) |
| 213 | + cherrypy.tools.secureheaders = cherrypy.Tool("before_finalize", secureheaders, priority=60) |
220 | 214 | webapp = GdashWeb() |
221 | 215 | webapp.api = GdashApis() |
222 | 216 | cherrypy.quickstart(webapp, "/", conf) |
|
0 commit comments