-
Notifications
You must be signed in to change notification settings - Fork 161
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
Request info on bytecode limitation #91
Comments
@jeremyben Thanks! This sounds like a feasible solution 🤔 . I have a similar idea( repacing string via function or buffer). But this still needs some validation experiments. I will try. Your idea is very constructive. |
It seems this works.
🙂 |
Hey I figured out a way to do it automatically with a dedicated tag. I use a tagged template that is a noop for development, but that is replaced at build time. export const __protect = (str: readonly string[], ...values: never[]) => String.raw({ raw: str })
// use it like so:
const key = __protect`secret_stuff` Since we only want to transform string constants, we forbid any interpolation thanks to Then I added a vite transform plugin to my configuration to replace the tagged strings with the buffer technique: /**
* @returns {import('vite').Plugin}
*/
function protectStringsInBytecode() {
const filter = vite.createFilter(/\.(m?[jt]s|[jt]sx)$/)
return {
name: 'protectString',
apply: 'build',
transform(code, id) {
if (!filter(id)) return
const replaced = code.replace(/__protect`(.+)`/gim, (_, str) => {
const { data } = Buffer.from(str).toJSON()
return `Buffer.from([${data.join(',')}]).toString()`
})
return replaced
},
}
} I think it could be added to your bytecode plugin as an option rather than a independant plugin. |
@jeremyben That's great. Thank you for taking the time to study this problem. I'll try again later. |
Be inspired by you! I found a better solution. Bytecode does not protect strings but numbers, so we can convert string to char code. The String.fromCharCode static method is great for this. For example: const encryptKey = 'ABC' ⬇️ const encryptKey = String.fromCharCode(65, 66, 67) This conversion method is very simple and does not require additional processing by developers. I will add an option( |
Yes that's simpler, maybe less runtime overhead but I can't say about that part. What would your api look like ? Be aware I also discovered that you should probably apply the escape sequences at build time the way the javascript engine does it, for example with windows paths ( |
New ver 1.0.19 is out! Support for protecting strings in v8 bytecode. But regular expression matching strings are not yet supported. Anyway, thank you @jeremyben . more details: https://evite.netlify.app/guide/source-code-protection.html#limitations-of-v8-bytecode |
You mention here that string contents are not protected in V8 bytecode:
https://evite.netlify.app/guide/source-code-protection.html#limitations-of-v8-bytecode
I was wondering if we could build a string from a buffer like so:
And the string would then be protected ?
Validations
The text was updated successfully, but these errors were encountered: