Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@madgex/safeguard
Advanced tools
A JavaScript library that tries to sandbox 3rd party content on a webpage
A JavaScript library that tries to sandbox 3rd party content on your webpage.
Sometimes you want to block the cascade in CSS, i.e. you want to inline some HTML and associated CSS in your page but don't want the CSS from the host page to affect it.
IFrames were meant for embedding 3rd party content on your page, right? Yes, but there are inherent issues with this:
Wrap any content in a <safe-guard>
custom element and watch as Safeguard yanks the content into either a ShadowDOM or a generated, src-less iframe.
npm install @madgex/safeguard
Either import the script of load from unpkg and you're set:
From CDN: Add the following script to the end of your section.
<script src="https://unpkg.com/@madgex/safeguard" defer></script>
From NPM: Install the package from NPM.
// App.js
import '@madgex/safeguard';
That's it. It will initialize itself.
You may have other blocks of HTML/CSS/JS to take along into the SafeGuard, you can tag
elements by wrapping them in HTML comments:
<html>
<head>
<title>My awesome page</title>
<!-- [sg:starttag:myWidget] -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
<!-- [sg:endtag:myWidget] -->
<link rel="stylesheet" href="/css/styles.css" />
</head>
<body>
...my document
<safe-guard tag="myWidget">
<h1>My document</h1>
<p>Once mounted in SafeGuard, I'll only have bootstrap CSS applied, and nothing from /css/styles.css.</p>
</safe-guard>
</body>
</html>
Any other elements to take along?
tag: null
Force using an iframe
iframe: false
If iframe, inject the iframe-resizer to adapt window height
iframeResizer: true
Option pass-through to iframe-resizer
iframeResizerOptions: {}
<safe-guard>
<p>No styling.</p>
</safe-guard>
Ensure the styles go with the content into ShadowDOM
<head>
<!-- [sg:starttag:myWidget] -->
<style>
.customStyles { color: red; }
</style>
<!-- [sg:endtag:myWidget] -->
</head>
<body>
…
<safe-guard tag="myWidget">
<p class="customStyles">Custom styling</p>
</safe-guard>
…
</body>
Force safeguard to use an iframe instead of ShadowDOM
<head>
<!-- [sg:starttag:myWidget] -->
<style>
.customStyles { color: red; }
</style>
<!-- [sg:endtag:myWidget] -->
</head>
<body>
…
<safe-guard iframe>
<p class="customStyles">Custom styling</p>
</safe-guard>
…
</body>
FAQs
A JavaScript library that tries to sandbox 3rd party content on a webpage
We found that @madgex/safeguard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.