Skip to content

Commit

Permalink
add santisation for handlebar template
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo committed Jan 6, 2025
1 parent c9a71cd commit 3a03592
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export const composeContext = ({
template: string;
templatingEngine?: "handlebars";
}) => {

// Sanitize the template by only allowing specific patterns
if (!/^[^{]*{{[\s\w]+}}[^}]*$/.test(template)) {
throw new Error("Invalid template format. Only simple variable substitutions are allowed.");
}

if (templatingEngine === "handlebars") {
const templateFunction = handlebars.compile(template);
return templateFunction(state);
Expand Down

0 comments on commit 3a03592

Please sign in to comment.