Socket
Socket
Sign inDemoInstall

node-iframe

Package Overview
Dependencies
26
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.2 to 1.4.0

6

dist/cache/cache.js

@@ -5,2 +5,4 @@ "use strict";

var config_1 = require("@app/config");
var appCache;
exports.appCache = appCache;
function _extractValidNodeCacheOptions(options) {

@@ -14,4 +16,2 @@ return Object.keys(options).reduce(function (object, key) {

}
var appCache;
exports.appCache = appCache;
function createCache() {

@@ -27,3 +27,3 @@ if (!config_1.cacheConfig.disabled) {

config_1.cacheConfig.disabled = !!options.disabled;
options.disabled ? (exports.appCache = appCache = {}) : createCache();
options.disabled ? (exports.appCache = appCache = undefined) : createCache();
}

@@ -30,0 +30,0 @@ if (!config_1.cacheConfig.disabled) {

"use strict";
exports.__esModule = true;
exports.url = void 0;
exports.url = process.env.API_URL ||
exports.url = exports.defaultInlineConfig = exports.defaultCorsConfig = exports.defaultConfig = void 0;
var url = process.env.API_URL ||
(process.env.NODE_ENV === "test" ? "https://www.drake.com" : "");
exports.url = url;
var defaultInlineConfig = {
script: false,
link: false
};
exports.defaultInlineConfig = defaultInlineConfig;
var defaultCorsConfig = {
script: false,
link: false,
img: false,
audio: false,
video: false
};
exports.defaultCorsConfig = defaultCorsConfig;
var defaultConfig = {
inline: defaultInlineConfig,
cors: defaultCorsConfig
};
exports.defaultConfig = defaultConfig;
//# sourceMappingURL=config.js.map

@@ -17,3 +17,6 @@ "use strict";

var config_1 = require("./config");
__createBinding(exports, config_1, "defaultConfig");
__createBinding(exports, config_1, "defaultCorsConfig");
__createBinding(exports, config_1, "defaultInlineConfig");
__createBinding(exports, config_1, "url");
//# sourceMappingURL=index.js.map
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -42,3 +53,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

exports.__esModule = true;
exports.configureCacheControl = exports.configureTemplates = exports.fetchFrame = void 0;
exports.fetchFrame = exports.configureCacheControl = exports.configureTemplates = exports.configureResourceControl = exports.appSourceConfig = void 0;
var is_url_1 = __importDefault(require("is-url"));

@@ -52,3 +63,5 @@ var isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch"));

exports.configureCacheControl = cache_1.configureCacheControl;
function manipulateSource(i, src, url, $html) {
var appSourceConfig = config_1.defaultConfig;
exports.appSourceConfig = appSourceConfig;
function manipulateSource(_, src, url, $html) {
if (src) {

@@ -60,3 +73,3 @@ var trailing_1 = src && src[0] === "/";

return __awaiter(this, void 0, void 0, function () {
var pathUrl, scriptCode, scriptText;
var pathUrl, res, source;
return __generator(this, function (_a) {

@@ -71,7 +84,7 @@ switch (_a.label) {

case 1:
scriptCode = _a.sent();
return [4, scriptCode.text()];
res = _a.sent();
return [4, res.text()];
case 2:
scriptText = _a.sent();
$html("script[src=\"" + src + "\"]").html(scriptText);
source = _a.sent();
$html("script[src=\"" + src + "\"]").html(source);
return [2];

@@ -98,8 +111,8 @@ }

function renderHtml(_a, server) {
var url = _a.url, baseHref = _a.baseHref;
var url = _a.url, baseHref = _a.baseHref, config = _a.config;
if (server === void 0) { server = false; }
return __awaiter(this, void 0, void 0, function () {
var cachedHtml, e_1, response, html, $html_1, e_2;
return __generator(this, function (_b) {
switch (_b.label) {
var cachedHtml, e_1, _b, inline, cors, inlineScripts, inlineLinks, corsScripts, response, html, $html_1, e_2;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:

@@ -110,8 +123,8 @@ if (!is_url_1["default"](url)) {

if (!(!config_1.cacheConfig.disabled && (cache_1.appCache === null || cache_1.appCache === void 0 ? void 0 : cache_1.appCache.get))) return [3, 4];
_b.label = 1;
_c.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
_c.trys.push([1, 3, , 4]);
return [4, (cache_1.appCache === null || cache_1.appCache === void 0 ? void 0 : cache_1.appCache.get(url))];
case 2:
cachedHtml = _b.sent();
cachedHtml = _c.sent();
if (cachedHtml) {

@@ -122,7 +135,15 @@ return [2, cheerio_1.load(cachedHtml)];

case 3:
e_1 = _b.sent();
e_1 = _c.sent();
console.error(e_1);
return [3, 4];
case 4:
_b.trys.push([4, 7, , 8]);
_b = {
inline: __assign(__assign({}, appSourceConfig.inline), config === null || config === void 0 ? void 0 : config.inline),
cors: __assign(__assign({}, appSourceConfig.cors), config === null || config === void 0 ? void 0 : config.cors)
}, inline = _b.inline, cors = _b.cors;
inlineScripts = inline.script, inlineLinks = inline.link;
corsScripts = cors.script;
_c.label = 5;
case 5:
_c.trys.push([5, 8, , 9]);
return [4, isomorphic_unfetch_1["default"](url, {

@@ -132,17 +153,27 @@ uri: url,

})];
case 5:
response = _b.sent();
case 6:
response = _c.sent();
return [4, response.text()];
case 6:
html = _b.sent();
case 7:
html = _c.sent();
$html_1 = cheerio_1.load(html);
if ($html_1) {
if (!!baseHref) {
$html_1("head").prepend("<base target=\"_self\" href=\"" + url + "\">");
if (typeof baseHref !== "undefined" && baseHref !== "false") {
$html_1("script").attr("src", function (i, src) {
return manipulateSource(i, src, url, $html_1);
});
}
!config_1.cacheConfig.disabled && (cache_1.appCache === null || cache_1.appCache === void 0 ? void 0 : cache_1.appCache.set(url, $html_1.html()));
}
if (inlineScripts) {
$html_1("script").attr("src", function (i, src) {
return manipulateSource(i, src, url, $html_1);
});
}
if (inlineLinks) {
$html_1("link").attr("href", function (i, src) {
return manipulateSource(i, src, url, $html_1);
});
}
if (corsScripts) {
$html_1("script").attr("crossorigin", corsScripts);
}
if (!config_1.cacheConfig.disabled) {
cache_1.appCache === null || cache_1.appCache === void 0 ? void 0 : cache_1.appCache.set(url, $html_1.html());
}
if (server) {

@@ -152,7 +183,7 @@ $html_1.status = 200;

return [2, $html_1];
case 7:
e_2 = _b.sent();
case 8:
e_2 = _c.sent();
console.error(e_2);
return [3, 8];
case 8: return [2, renderErrorHtml({ url: url, server: server, noPage: true })];
return [3, 9];
case 9: return [2, renderErrorHtml({ url: url, server: server, noPage: true })];
}

@@ -192,3 +223,10 @@ });

exports.fetchFrame = fetchFrame;
function configureResourceControl(appConfig) {
exports.appSourceConfig = appSourceConfig = Object.assign({}, config_1.defaultConfig, {
cors: __assign(__assign({}, config_1.defaultCorsConfig), appConfig === null || appConfig === void 0 ? void 0 : appConfig.cors),
inline: __assign(__assign({}, config_1.defaultInlineConfig), appConfig === null || appConfig === void 0 ? void 0 : appConfig.inline)
});
}
exports.configureResourceControl = configureResourceControl;
exports["default"] = createIframe;
//# sourceMappingURL=iframe.js.map
{
"name": "node-iframe",
"version": "1.3.2",
"version": "1.4.0",
"description": "create a iframe on your server to bypass CORS issues. ( reverse engineer security issues )",

@@ -26,2 +26,3 @@ "main": "dist/iframe.js",

"dotenv": "^8.2.0",
"express": "^4.17.1",
"jest": "^26.4.0",

@@ -28,0 +29,0 @@ "ts-jest": "^26.4.1",

@@ -13,3 +13,3 @@ # node-iframe

On your server
On your server if using with express

@@ -24,3 +24,4 @@ ```typescript

url: req.query.url,
baseHref: req.query.baseHref, // optional,
baseHref: req.query.baseHref, // optional determine how to control link redirects,
config: JSON.parse(req.query.config), // parse config if sent as query,
})

@@ -30,3 +31,3 @@ );

On the client use directly in your iframe if your api is on the same server set the url below like this or if your using a framework like gatsby, nextjs, etc
On the client use directly in your iframe if your api is on the same server set the url below like this or if your using a framework like gatsby, nextjs, etc or non-express apps

@@ -42,2 +43,3 @@ ```html

fetchFrame,
configureResourceControl,
configureCacheControl,

@@ -47,2 +49,7 @@ configureTemplates,

// optional: configure if element should be inlined, cors, etc
configureResourceControl({
inline: { script: true, link: false },
cors: { script: true },
});
// optional: configure cache-control, to disable cache set `disabled` to true - check https://github.com/node-cache/node-cache#options

@@ -57,3 +64,3 @@ // for more options and info

async function fetchIframe() {
return await fetchFrame("/iframe/?url=https://www.etsy.com");
return await fetchFrame({ url: "https://www.etsy.com" });
}

@@ -64,12 +71,4 @@ ```

## Params
Node iframe has one param Object with a `url` prop that is the url of the website and `baseHref` is optional property that will inject crossorigin="anonymous" onto all your script tags.
## About
This project uses cheerio to manipulate html very fast. If your iframe fails to render thats where the security issues need to be reverse hacked by us using this project. As an alternative solution if the iframe fails to load simply fall back to the normal url of web page. You can fire this as an api request directly with `fetch` to get the website as html or use directly as your iframe src for best performance.
## License
MIT

@@ -1,1 +0,26 @@

export declare const url: string;
declare const url: string;
declare const defaultInlineConfig: {
script: boolean;
link: boolean;
};
declare const defaultCorsConfig: {
script: boolean;
link: boolean;
img: boolean;
audio: boolean;
video: boolean;
};
declare const defaultConfig: {
inline: {
script: boolean;
link: boolean;
};
cors: {
script: boolean;
link: boolean;
img: boolean;
audio: boolean;
video: boolean;
};
};
export { defaultConfig, defaultCorsConfig, defaultInlineConfig, url };
export { stdTTL, checkperiod, cacheConfig } from "./cache";
export { headers } from "./headers";
export { url } from "./config";
export { defaultConfig, defaultCorsConfig, defaultInlineConfig, url, } from "./config";
import { configureTemplates } from "@app/templates";
import { configureCacheControl } from "@app/cache";
interface InlineElementsConfig {
script?: boolean;
link?: boolean;
}
declare type CorsResourceType = "anonymous" | "use-credentials" | boolean;
interface CorsElementsConfig {
audio?: CorsResourceType;
link?: CorsResourceType;
img?: CorsResourceType;
script?: CorsResourceType;
video?: CorsResourceType;
}
interface RenderHtmlConfig {
inline?: InlineElementsConfig;
cors?: CorsElementsConfig;
}
declare let appSourceConfig: {
inline: {
script: boolean;
link: boolean;
};
cors: {
script: boolean;
link: boolean;
img: boolean;
audio: boolean;
video: boolean;
};
};
declare function createIframe(req: any, res: any, next: any): void;
export declare function fetchFrame(model: any): Promise<any>;
export { configureTemplates, configureCacheControl };
declare function fetchFrame(model: any): Promise<any>;
declare function configureResourceControl(appConfig: RenderHtmlConfig): void;
export { appSourceConfig, configureResourceControl, configureTemplates, configureCacheControl, fetchFrame, };
export default createIframe;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc