astro-accelerator 6.0.2 → 6.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "6.0.2",
2
+ "version": "6.0.3",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -33,6 +33,7 @@ function setClickableBlocks() {
33
33
  /**
34
34
  * Handles the block-level clicks
35
35
  *
36
+ * @this {HTMLElement}
36
37
  * @param {Event} e
37
38
  * @returns
38
39
  */
@@ -40,10 +41,16 @@ function handleClick(e) {
40
41
  const location = this.getAttribute(dataAttributeName);
41
42
 
42
43
  if (location) {
43
- e.preventDefault();
44
- document.location = location;
45
- return false;
44
+ // Ensure links are same origin
45
+ const isSafeUrl = location.startsWith('/') || location.startsWith(window.location.origin);
46
+
47
+ if (isSafeUrl) {
48
+ e.preventDefault();
49
+ document.location = location;
50
+ return false;
51
+ }
46
52
  }
47
53
  }
48
54
 
55
+
49
56
  export { setClickableBlocks };
@@ -9,6 +9,18 @@
9
9
 
10
10
  import { qsa } from './query.js';
11
11
 
12
+ /**
13
+ * Validates a YouTube video ID.
14
+ * @param {string | null} id
15
+ * @returns {boolean}
16
+ */
17
+ function isValidYoutubeId(id) {
18
+ if (!id) {
19
+ return false;
20
+ }
21
+ return /^[a-zA-Z0-9_-]{11}$/.test(id);
22
+ }
23
+
12
24
  function enhanceYoutubeLinks() {
13
25
  const videos = qsa('a[href^="https://www.youtube.com/watch?v="]');
14
26
 
@@ -19,6 +31,11 @@ function enhanceYoutubeLinks() {
19
31
  }
20
32
 
21
33
  const id = new URL(video.href).searchParams.get('v');
34
+
35
+ if (!id || !isValidYoutubeId(id)) {
36
+ continue;
37
+ }
38
+
22
39
  video.setAttribute('data-youtube', id);
23
40
  video.classList.add('init');
24
41
  video.setAttribute('role', 'button');
@@ -29,8 +46,12 @@ function enhanceYoutubeLinks() {
29
46
  </div>`;
30
47
  }
31
48
 
49
+ /**
50
+ * @param {Event} event
51
+ */
32
52
  function clickHandler(event) {
33
- var link = event.target.closest('[data-youtube]');
53
+ var target = /** @type {HTMLElement} */ (event.target);
54
+ var link = target && target.closest ? target.closest('[data-youtube]') : null;
34
55
 
35
56
  if (!link) {
36
57
  return;
@@ -39,6 +60,10 @@ function enhanceYoutubeLinks() {
39
60
  event.preventDefault();
40
61
  var id = link.getAttribute('data-youtube');
41
62
 
63
+ if (!id || !isValidYoutubeId(id)) {
64
+ return;
65
+ }
66
+
42
67
  var player = document.createElement('div');
43
68
  player.innerHTML = `<iframe class="yt-iframe" width="560" height="315" src="https://www.youtube-nocookie.com/embed/${id}?autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
44
69