xframe.js 527 B

123456789101112131415161718
  1. 'use strict';
  2. const utils = require('../utils');
  3. module.exports = options => {
  4. return async function xframe(ctx, next) {
  5. await next();
  6. const opts = utils.merge(options, ctx.securityOptions.xframe);
  7. if (utils.checkIfIgnore(opts, ctx)) return;
  8. // DENY,SAMEORIGIN,ALLOW-FROM
  9. // https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options?redirectlocale=en-US&redirectslug=The_X-FRAME-OPTIONS_response_header
  10. const value = opts.value || 'SAMEORIGIN';
  11. ctx.set('x-frame-options', value);
  12. };
  13. };