Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(security): add injection prevention #139

Merged
merged 9 commits into from
Sep 12, 2023
15 changes: 15 additions & 0 deletions source/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,18 @@ export class Session {
});
}
}

export function prepared(
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
literals: TemplateStringsArray,
...placeholders: string[]
) {
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
let result = "";

for (let i = 0; i < placeholders.length; i++) {
result += literals[i];
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
result += placeholders[i].replace(/'/g, "\\'").replace(/"/g, '\\"');
ffMathy marked this conversation as resolved.
Show resolved Hide resolved
}

result += literals[literals.length - 1];
return result;
}