forked from Uninett/nav
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support X-Frame-Options with a default of SAMEORIGIN.
- Loading branch information
Showing
2 changed files
with
24 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
from pathlib import Path | ||
|
||
from nav.config import NAVConfigParser | ||
from nav.config import NavConfigParserDefaultSection | ||
|
||
|
||
class WebSecurityConfigParser(NAVConfigParser): | ||
class WebSecurityConfigParser(NavConfigParserDefaultSection): | ||
SECTION = "security" | ||
DEFAULT_CONFIG_FILES = [str(Path('webfront') / 'webfront.conf')] | ||
DEFAULT_CONFIG = u""" | ||
[security] | ||
tls=off | ||
allow_frames=self | ||
""" | ||
FRAMES_OPTION = 'allow_frames' | ||
FRAMES_DEFAULT = 'self' | ||
|
||
def __init__(self): | ||
super().__init__(self.SECTION) | ||
|
||
# clickjacking-settings | ||
|
||
def get_x_frame_options(self): | ||
"Translate CSP frame ancestors to the old X-Frame-Options header" | ||
frames_flag = self.get(self.FRAMES_OPTION) or self.FRAMES_DEFAULT | ||
if frames_flag == 'none': | ||
return 'DENY' | ||
return 'SAMEORIGIN' |