Skip to content

validate digest lengths #5

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

Open
flokli opened this issue Jan 31, 2023 · 4 comments · May be fixed by #15
Open

validate digest lengths #5

flokli opened this issue Jan 31, 2023 · 4 comments · May be fixed by #15
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@flokli
Copy link
Contributor

flokli commented Jan 31, 2023

Currently this crate does not validate the SSRI hashes to actually encode a digest that matches the size of the hash function used.

This means, the following SSRI succeds to parse:

sha256-pc6cFV7Qk5dhRkbJcX/HzZSxAj17drYY1Ank

… even though this only encodes 27 bytes, not 32:

❯ echo -n pc6cFV7Qk5dhRkbJcX/HzZSxAj17drYY1Ank | base64 -d | hexdump -C
00000000  a5 ce 9c 15 5e d0 93 97  61 46 46 c9 71 7f c7 cd  |....^...aFF.q...|
00000010  94 b1 02 3d 7b 76 b6 18  d4 09 e4                 |...={v.....|
0000001b

I'd expect this to fail.

@zkat zkat added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Jan 31, 2023
@zkat
Copy link
Owner

zkat commented Jan 31, 2023

I guess in the use cases I was using this for, there wasn't any knock-on effect of this happening. If they were longer or shorter didn't really affect the security of the result (as far as any way I could tell), but I can see how having this guarantee would bring peace of mind. Do you have a specific use case where this would cause problems for you? I guess if you're expecting general validation of these as-is...

@flokli
Copy link
Contributor Author

flokli commented Jan 31, 2023

I guess what makes this complicated is that you probably end up having to decode the base64 string, pulling in some more crates to do this properly.

I'm fine to do the base64 decoding and comparison against expected digest sizes outside, but I guess then it should be documented this crate doesn't do any further sanitization of the encoded digest.

@flokli
Copy link
Contributor Author

flokli commented Feb 1, 2023

I opened #6 to add this remark to the docs.

I also saw you already do pull in the base64 crate - in that case, it could probably be done easily.

I won't implement that though, as I ended up not being able to use this crate - the SRI hashes I needed to decode can also be md5 unfortunately (which is not supported by this crate), and don't support multiple hashes per string (which is unfortunate) - in the end it was easier to just write my own small decoder.

zkat pushed a commit that referenced this issue Feb 1, 2023
@zkat
Copy link
Owner

zkat commented Feb 1, 2023

yeah it's not a super complicated thing to roll up yourself, for the most part. :)

selfisekai added a commit to selfisekai/ssri-rs that referenced this issue Dec 5, 2024
BREAKING CHANGE: new type signature of Hash, digest lengths are now validated

Fixes: zkat#5
@selfisekai selfisekai linked a pull request Dec 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants