Skip to content

Commit a62ef17

Browse files
authored
Merge pull request #49 from FriendsOfREDAXO/copilot/fix-inline-styles-security-headers
Fix CSP inline style violations - Remove inline styles for Content Security Policy compliance
2 parents 036dd36 + 27758c8 commit a62ef17

7 files changed

Lines changed: 118 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ modules.xml
1313
.idea/encodings.xml
1414
*.ipr
1515
node_modules/
16+
build/dist/
17+
build/node_modules/

assets/vidstack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16243,7 +16243,7 @@
1624316243

1624416244
${DefaultControlsSpacer()}
1624516245

16246-
<media-controls-group class="vds-controls-group" style="pointer-events: none;">
16246+
<media-controls-group class="vds-controls-group">
1624716247
${[
1624816248
DefaultControlsSpacer(),
1624916249
DefaultPlayButton({ tooltip: "top" }),
@@ -21180,7 +21180,7 @@
2118021180
static tagName = "media-slider";
2118121181
};
2118221182
var videoTemplate = /* @__PURE__ */ createTemplate(
21183-
`<video muted playsinline preload="none" style="max-width: unset;"></video>`
21183+
`<video muted playsinline preload="none"></video>`
2118421184
);
2118521185
var MediaSliderVideoElement = class extends Host(HTMLElement, SliderVideo) {
2118621186
static tagName = "media-slider-video";

assets/vidstack_helper.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,12 @@ noscript .js .a11y-content {
187187
background-color: #117a8b;
188188
color: white;
189189
}
190+
191+
/* CSP-compliant styles to replace inline styles */
192+
.vds-controls-group {
193+
pointer-events: none;
194+
}
195+
196+
media-slider-video video {
197+
max-width: unset;
198+
}

assets/vs_js_out.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11556,7 +11556,7 @@
1155611556

1155711557
${DefaultControlsSpacer()}
1155811558

11559-
<media-controls-group class="vds-controls-group" style="pointer-events: none;">
11559+
<media-controls-group class="vds-controls-group">
1156011560
${[
1156111561
DefaultControlsSpacer(),
1156211562
DefaultPlayButton({ tooltip: "top" }),
@@ -16555,7 +16555,7 @@
1655516555
static tagName = "media-slider";
1655616556
};
1655716557
videoTemplate = /* @__PURE__ */ createTemplate(
16558-
`<video muted playsinline preload="none" style="max-width: unset;"></video>`
16558+
`<video muted playsinline preload="none"></video>`
1655916559
);
1656016560
MediaSliderVideoElement = class extends Host(HTMLElement, SliderVideo) {
1656116561
static tagName = "media-slider-video";

build/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Vidstack Build Directory
2+
3+
This directory contains the build configuration and scripts for the Vidstack addon.
4+
5+
## Building
6+
7+
To build the assets, run:
8+
9+
```bash
10+
npm install
11+
npm run build
12+
```
13+
14+
This will:
15+
1. Bundle the vidstack components (`vidstack.js`)
16+
2. Bundle the vidstack JavaScript (`vs_js_out.js`)
17+
3. Remove inline styles for CSP compliance
18+
19+
## CSP Compliance
20+
21+
The `remove-inline-styles.js` script automatically removes inline styles from the built files to ensure Content Security Policy (CSP) compliance. The following inline styles are removed:
22+
23+
- `style="pointer-events: none;"` from `media-controls-group` elements
24+
- `style="max-width: unset;"` from `video` elements
25+
26+
These styles are replaced by CSS rules in `assets/vidstack_helper.css`:
27+
28+
```css
29+
.vds-controls-group {
30+
pointer-events: none;
31+
}
32+
33+
media-slider-video video {
34+
max-width: unset;
35+
}
36+
```
37+
38+
## Output
39+
40+
The built files are placed in the `dist/` directory and should be copied to the `assets/` directory for deployment.
41+
42+
**Note:** The `dist/` and `node_modules/` directories are excluded from git via `.gitignore`.

build/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"build_components": "esbuild config/vs_components.js --bundle --outfile=dist/vidstack.js",
1111
"build_js": "esbuild config/vs_js.js --bundle --outfile=dist/vs_js_out.js",
12-
"build": "npm run build_components && npm run build_js"
12+
"remove_inline_styles": "node remove-inline-styles.js",
13+
"build": "npm run build_components && npm run build_js && npm run remove_inline_styles"
1314
}
1415
}

build/remove-inline-styles.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Post-build script to remove inline styles for CSP compliance
5+
* This script removes inline style attributes that violate Content Security Policy
6+
*/
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
11+
const files = [
12+
'./dist/vidstack.js',
13+
'./dist/vs_js_out.js'
14+
];
15+
16+
console.log('Removing inline styles for CSP compliance...\n');
17+
18+
files.forEach(file => {
19+
const filePath = path.join(__dirname, file);
20+
21+
if (!fs.existsSync(filePath)) {
22+
console.log(`⚠️ File not found: ${file}`);
23+
return;
24+
}
25+
26+
let content = fs.readFileSync(filePath, 'utf8');
27+
let modified = false;
28+
29+
// Remove pointer-events: none inline style
30+
const beforePointerEvents = content;
31+
content = content.replace(
32+
/(<media-controls-group[^>]*class="vds-controls-group"[^>]*)\s+style="pointer-events:\s*none;?"/gi,
33+
'$1'
34+
);
35+
if (content !== beforePointerEvents) {
36+
console.log(`✓ Removed pointer-events inline style from ${file}`);
37+
modified = true;
38+
}
39+
40+
// Remove max-width: unset inline style
41+
const beforeMaxWidth = content;
42+
content = content.replace(
43+
/(<video[^>]*)\s+style="max-width:\s*unset;?"/gi,
44+
'$1'
45+
);
46+
if (content !== beforeMaxWidth) {
47+
console.log(`✓ Removed max-width inline style from ${file}`);
48+
modified = true;
49+
}
50+
51+
if (modified) {
52+
fs.writeFileSync(filePath, content, 'utf8');
53+
console.log(`✓ Updated ${file}\n`);
54+
} else {
55+
console.log(`ℹ No inline styles found in ${file}\n`);
56+
}
57+
});
58+
59+
console.log('Done! All inline styles removed for CSP compliance.');

0 commit comments

Comments
 (0)