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

operating on source text with TextEncoder is error-prone when dealing with special characters like the Byte-Order-Mark #128

Open
mozfreddyb opened this issue Mar 11, 2022 · 0 comments

Comments

@mozfreddyb
Copy link

Hi,

As the spec co-author of SRI and maintainer of srihash.org, I was curious enough to look at your source code and noticed a pattern that was really hard to debug on our end, so here's my write-up, in the hope of making things a bit easier on your end.

Background: The website srihash.org provides an input field and computes the integrity metadata (shaXYZ-1234) for you. Oddly, some resources hashed really differently on the website than they did with curl | openssl ....

What we found is that we had been using the TextEncoder interface, which is swalloing the byte-order-mark character. E.g., When passing JavaScript source code like \xFEFFfoo into the TextEncoder API, you would receive the ArrayBuffer for foo.

We fixed the issue by not encoding things ourselves, but fetch()ing and awaiting the respone's .arrayBuffer(). Operating on that ArrayBuffer with crypto.subtle.digest() worked.

Further info is in our commit and our related issue mozilla/srihash.org#524

@mozfreddyb mozfreddyb changed the title operating on source text with TextEncoder is error-rpone when facing special characters like the Byte-Order-Marks operating on source text with TextEncoder is error-prone when dealing with special characters like the Byte-Order-Mark Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant