diff --git a/src/scripts/components/button-component.ts b/src/scripts/components/button-component.ts index 3dc55f2..f9614d2 100644 --- a/src/scripts/components/button-component.ts +++ b/src/scripts/components/button-component.ts @@ -1,3 +1,5 @@ +import { escapeHtml, escapeHtmlAttribute, sanitizeUrl } from '../utils/html'; + export default class ButtonComponent extends HTMLElement { static get observedAttributes() { return ['href', 'title']; @@ -16,16 +18,19 @@ export default class ButtonComponent extends HTMLElement { } render() { - const href = this.getAttribute('href') || '#'; - const title = this.getAttribute('title') || ''; + const href = escapeHtmlAttribute( + sanitizeUrl(this.getAttribute('href') || '#') + ); + const title = escapeHtml(this.getAttribute('title') || ''); this.innerHTML = ` - - `; + + ${title} + + `; } } diff --git a/src/scripts/components/card-component.ts b/src/scripts/components/card-component.ts index 97ab3c8..572673f 100644 --- a/src/scripts/components/card-component.ts +++ b/src/scripts/components/card-component.ts @@ -1,3 +1,10 @@ +import { + escapeHtml, + escapeHtmlAttribute, + sanitizeAssetUrl, + sanitizeUrl, +} from '../utils/html'; + class CardComponent extends HTMLElement { static get observedAttributes() { return ['imgsrc', 'href', 'title', 'description']; @@ -16,18 +23,25 @@ class CardComponent extends HTMLElement { } render() { - const imgSrc = this.getAttribute('imgsrc'); // 없으면 null - const href = this.getAttribute('href') || '#'; - const title = this.getAttribute('title') || ''; - const description = this.getAttribute('description') || ''; + const imgSrc = this.getAttribute('imgsrc'); + const safeImgSrc = imgSrc + ? escapeHtmlAttribute(sanitizeAssetUrl(imgSrc, '')) + : null; + const href = escapeHtmlAttribute( + sanitizeUrl(this.getAttribute('href') || '#') + ); + const rawTitle = this.getAttribute('title') || ''; + const title = escapeHtml(rawTitle); + const titleAttribute = escapeHtmlAttribute(rawTitle); + const description = escapeHtml(this.getAttribute('description') || ''); this.innerHTML = `