diff --git a/src/api/badge.js b/src/api/badge.js
index 8dccff0..cbe890b 100644
--- a/src/api/badge.js
+++ b/src/api/badge.js
@@ -1,5 +1,6 @@
const router = require('express').Router();
const axios = require('axios');
+const { escapeSvg, safeColor } = require('../lib/sanitize');
router.get('/badge', async (req, res) => {
const {
@@ -16,7 +17,8 @@ router.get('/badge', async (req, res) => {
try {
// download icon SVG from SimpleIcons CDN
- const iconUrl = `https://cdn.simpleicons.org/${icon}?viewbox=auto&size=${size}`;
+ const safeIcon = escapeSvg(icon);
+ const iconUrl = `https://cdn.simpleicons.org/${safeIcon}?viewbox=auto&size=${size}`;
const iconResponse = await axios.get(iconUrl, { responseType: 'text' });
if (iconResponse.status !== 200) {
return res.status(404).send('Icon not found');
@@ -33,6 +35,11 @@ router.get('/badge', async (req, res) => {
}
// Badge size
+ const safeLabel = escapeSvg(effectiveLabel);
+ const safeBgIcon = safeColor(bgicon, 'none');
+ const safeBgLabel = safeColor(bglabel, 'none');
+ const safeFontWeight = escapeSvg(fontweight);
+
const padding = 10;
const iconSize = parseInt(size);
const fontSize = Math.round(iconSize * 0.6);
@@ -63,6 +70,7 @@ router.get('/badge', async (req, res) => {
effectiveColor = "#222"; // fallback
}
}
+ effectiveColor = safeColor(effectiveColor, '#222');
// doboz magasság 5 pixellel nagyobb legyen az ikon méreténél
const iconSizeAndPadding = iconSize + 5;
@@ -71,14 +79,14 @@ router.get('/badge', async (req, res) => {
let width, height, iconGroup, textElem;
const fontFamily = "Verdana,Geneva,DejaVu Sans,sans-serif";
- const fontWeight = fontweight; // paraméterből
+ const fontWeight = safeFontWeight; // paraméterből
if (labelpos === 'left') {
// Külön dobozok: padding csak a széleken kell, a dobozokon belül nem!
- textElem = `
- ${effectiveLabel}`;
+ textElem = `
+ ${safeLabel}`;
iconGroup = `
-
+
${iconSVG}
`;
} else if (labelpos === 'above' || labelpos === 'below') {
@@ -94,9 +102,9 @@ router.get('/badge', async (req, res) => {
height = iconSizeAndPadding + textPadding + labelRectHeight;
// Label háttér
- const labelRect = ``;
+ const labelRect = ``;
// Ikon háttér
- const iconRect = ``;
+ const iconRect = ``;
// Szöveg
const textY = labelpos === 'above'
@@ -104,7 +112,7 @@ router.get('/badge', async (req, res) => {
: labelRectY + 5 + labelRectHeight / 2;
textElem = `
${labelRect}
- ${effectiveLabel}
+ ${safeLabel}
`;
// Ikon
@@ -115,11 +123,11 @@ router.get('/badge', async (req, res) => {
} else {
// Alapértelmezett: ikon balra, szöveg jobbra (függőleges közép)
iconGroup = `
-
+
${iconSVG}
`;
- textElem = `
- ${effectiveLabel}`;
+ textElem = `
+ ${safeLabel}`;
}
// SVG badge string összefűzéssel, szöveg árnyékkal
diff --git a/src/api/tag.js b/src/api/tag.js
index 1de57bf..83c0e45 100644
--- a/src/api/tag.js
+++ b/src/api/tag.js
@@ -1,4 +1,5 @@
const router = require('express').Router();
+const { escapeSvg, safeColor } = require('../lib/sanitize');
router.get('/tag', (req, res) => {
@@ -15,7 +16,12 @@ router.get('/tag', (req, res) => {
} = req.query;
const fontFamily = "Verdana,Geneva,DejaVu Sans,sans-serif";
- const fontWeight = fontweight;
+ const fontWeight = escapeSvg(fontweight);
+ const safeTag = escapeSvg(tag);
+ const safeLabel = escapeSvg(label);
+ const safeColorVal = safeColor(color, '#000000');
+ const safeBgTag = safeColor(bgtag, 'none');
+ const safeBgLabel = safeColor(bglabel, 'none');
// A flat badge esetén a szöveg középre igazítása miatt a szöveg pozícióját módosítjuk
//const labelX = labelpos === 'left' ? 165 : 455;
@@ -33,12 +39,12 @@ router.get('/tag', (req, res) => {
const rect = `
-
-
+
+
- ${tag.toLowerCase()}
- ${label.toUpperCase()}
+ ${safeTag.toLowerCase()}
+ ${safeLabel.toUpperCase()}
`.trim();
@@ -56,15 +62,15 @@ router.get('/tag', (req, res) => {
- ${tag}
- ${tag}
- ${label}
- ${label}
+ ${safeTag}
+ ${safeTag}
+ ${safeLabel}
+ ${safeLabel}
`.trim();
const svg = `
-