Skip to content

Commit

Permalink
Better hashed iv from the queryString;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Dec 11, 2023
1 parent 201f2a0 commit 04a8cec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions packages/js-lib/src/core/InterceptionEncryptionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ export const encryptData = async (data: string, iv: Uint8Array, ss: Uint8Array)
export const buildIvFromQueryString = async (querystring: string) => {
const searchParams = new URLSearchParams(querystring);

const uniqueQueryKey =
searchParams.get('fileId') || (searchParams.has('alias') ? querystring : undefined);
const uniqueQueryKey = (() => {
// Check if it's a direct file request
if (searchParams.has('fileId'))
return `${searchParams.get('fileId')} ${
searchParams.get('key') || searchParams.get('payloadKey')
}-${searchParams.get('height')}x${searchParams.get('width')}`;
// Check if it's a query-batch/modifed request; Queries on a single drive (alias)
else if (searchParams.has('alias')) return querystring;
// undefined => and we'll use a random IV
else return undefined;
})();

const hashedQueryKey =
uniqueQueryKey && typeof crypto.subtle.digest !== 'undefined'
Expand Down

0 comments on commit 04a8cec

Please sign in to comment.