├── .gitignore ├── .travis.yml ├── package.json ├── index.js ├── LICENSE ├── README.md └── test └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.log 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.12" 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frameguard", 3 | "author": "Adam Baldwin (http://andyet.net/team/baldwin)", 4 | "contributors": [ 5 | "Evan Hahn (http://evanhahn.com)" 6 | ], 7 | "description": "Middleware to set X-Frame-Options headers", 8 | "version": "0.2.2", 9 | "keywords": [ 10 | "helmet", 11 | "security", 12 | "express", 13 | "connect", 14 | "x-frame-options", 15 | "clickjack", 16 | "frame" 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "git://github.com/helmetjs/frameguard.git" 21 | }, 22 | "bugs": "https://github.com/helmetjs/frameguard/issues", 23 | "scripts": { 24 | "test": "mocha" 25 | }, 26 | "devDependencies": { 27 | "connect": "^3.3.1", 28 | "mocha": "^2.0.1", 29 | "supertest": "^0.15.0" 30 | }, 31 | "dependencies": { 32 | "lodash.isstring": "3.0.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var isString = require('lodash.isstring'); 2 | 3 | module.exports = function frameguard(action, options) { 4 | 5 | var header; 6 | 7 | if (action === undefined) { 8 | header = 'SAMEORIGIN'; 9 | } else if (isString(action)) { 10 | header = action.toUpperCase(); 11 | } 12 | 13 | if (header === 'ALLOWFROM') { 14 | header = 'ALLOW-FROM'; 15 | } else if (header === 'SAME-ORIGIN') { 16 | header = 'SAMEORIGIN'; 17 | } 18 | 19 | if (['DENY', 'ALLOW-FROM', 'SAMEORIGIN'].indexOf(header) === -1) { 20 | throw new Error('X-Frame must be undefined, "DENY", "ALLOW-FROM", or "SAMEORIGIN"'); 21 | } 22 | 23 | if (header === 'ALLOW-FROM') { 24 | if (!isString(options)) { 25 | throw new Error('X-Frame: ALLOW-FROM requires a second parameter'); 26 | } 27 | header = 'ALLOW-FROM ' + options; 28 | } 29 | 30 | return function frameguard(req, res, next) { 31 | res.setHeader('X-Frame-Options', header); 32 | next(); 33 | }; 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Evan Hahn, Adam Baldwin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Frameguard 2 | 3 | [![Build Status](https://travis-ci.org/helmetjs/frameguard.svg?branch=master)](https://travis-ci.org/helmetjs/frameguard) 4 | 5 | **Trying to prevent:** Your page being put in a `` or `