Skip to content

Commit dd533f9

Browse files
hehoongraduta
andauthored
[OGUI-1861] Allow blob: in img-src CSP (#3237)
- Update Content-Security-Policy to permit `blob:` URLs for images only. The changes allow for Blob-based images to be previewed or downloaded. Other Blob types such as `script-src` are not permitted, mainly to prevent unwanted code execution via: ```js const blob = new Blob(['console.log(\'executed\')'], { type: 'application/javascript' }); ``` By default, Helmet's CSP middleware allows `"'self'", "data:"` in `img-src`, see: https://github.com/helmetjs/helmet/blob/dd6e18f735d61248f654df3960da80db7fb2120a/middlewares/content-security-policy/index.ts#L63. Do note that `blob:` URLs are entirely local to the browser. When you create a blob URL using `URL.createObjectURL(blob)`, the browser generates an internal reference to an in-memory `Blob` or `MediaSource` object. It cannot be used to fetch resources from another website. For more information, please see the documentation: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/blob --------- Co-authored-by: George Raduta <[email protected]>
1 parent 0a6b618 commit dd533f9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Framework/Backend/http/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ class HttpServer {
135135
* @param {number} config.port secure port number
136136
* @param {list} config.iframeCsp list of URLs for frame-src CSP
137137
* @param {boolean} config.allow allow unsafe-eval in CSP
138+
* @param {boolean} config.allowIframeCsp allow iframe embedding from given URLs
138139
*/
139-
configureHelmet({ hostname, port, iframeCsp = [], allow = false }) {
140+
configureHelmet({ hostname, port, iframeCsp = [], allow = false, allowIframeCsp = false }) {
140141
// Sets "X-Frame-Options: DENY" (doesn't allow to be in any iframe)
141142
this.app.use(helmet.frameguard({ action: 'deny' }));
142143
// Sets "Strict-Transport-Security: max-age=5184000 (60 days) (stick to HTTPS)
@@ -156,6 +157,7 @@ class HttpServer {
156157
directives: {
157158
/* eslint-disable */
158159
defaultSrc: ["'self'", "data:", hostname + ':*'],
160+
...(allowIframeCsp && { imgSrc: ["'self'", "data:", "blob:"] }),
159161
scriptSrc: ["'self'", ...(allow ? ["'unsafe-eval'"] : [])],
160162
styleSrc: ["'self'", "'unsafe-inline'"],
161163
connectSrc: ["'self'", 'http://' + hostname + ':' + port, 'https://' + hostname, 'wss://' + hostname, 'ws://' + hostname + ':' + port],

0 commit comments

Comments
 (0)