perf: 邮件模版安全优化

This commit is contained in:
xiaojunnuo
2025-12-05 00:45:56 +08:00
parent 43513049be
commit adca151e4f
2 changed files with 15 additions and 6 deletions
@@ -168,6 +168,7 @@ export class K8sClient {
const oldIngress = await client.readNamespacedIngress(ingressName, namespace); const oldIngress = await client.readNamespacedIngress(ingressName, namespace);
const newIngress = merge(oldIngress.body, opts.body); const newIngress = merge(oldIngress.body, opts.body);
const res = await client.replaceNamespacedIngress(ingressName, namespace, newIngress); const res = await client.replaceNamespacedIngress(ingressName, namespace, newIngress);
this.logger.info("ingress patched", opts.body); this.logger.info("ingress patched", opts.body);
return res; return res;
} }
@@ -1,6 +1,7 @@
import {AbstractTaskPlugin, FileItem, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline'; import {AbstractTaskPlugin, FileItem, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
import {CertInfo, CertReader} from "@certd/plugin-cert"; import {CertInfo, CertReader} from "@certd/plugin-cert";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { get } from 'lodash-es';
@IsTaskPlugin({ @IsTaskPlugin({
name: 'DeployCertToMailPlugin', name: 'DeployCertToMailPlugin',
@@ -176,11 +177,18 @@ export class DeployCertToMailPlugin extends AbstractTaskPlugin {
}) })
} }
compile(templateString:string) { compile(templateString: string) {
return new Function('data', ` with(data || {}) { // 1. 转义所有HTML特殊字符
return \`${templateString}\`;
} // 2. 使用更安全的方式替换变量
`); return function(data) {
} return templateString.replace(/\${(.*?)}/g, (match, key) => {
// 3. 安全地获取属性,避免原型链访问
const value = get(data, key, '');
// 4. 对值也进行转义
return String(value);
});
};
}
} }
new DeployCertToMailPlugin(); new DeployCertToMailPlugin();