Improve image signature handling and resizing functionality - #4511
Improve image signature handling and resizing functionality#4511conico974 wants to merge 4 commits into
Conversation
|
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Style invalidation on a large API referenceElements restyled by opening one popup on the Snyk API reference. A share near or above 100% means the insertion restyles the whole document.
|
|
|
||
| /** | ||
| * Compare two signatures in constant time, to avoid leaking a valid signature byte by byte. | ||
| * We can't use `node:crypto`'s `timingSafeEqual` as this also runs on the edge runtime. |
There was a problem hiding this comment.
Can't you use an equivalent of https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#timingsafeequal?
There was a problem hiding this comment.
I don't think it's available in vercel...
| case ImageRejectReason.UpstreamError: | ||
| // this one can happen for a lot of reasons, so we fallback to a redirect to the original image | ||
| // It sometimes happen when upstream block fetch from our server | ||
| throw new Error('Upstream error, falling back to a redirect'); | ||
| case ImageRejectReason.UnsupportedContentType: | ||
| throw new Error('Unsupported content type, falling back to a redirect'); | ||
| case ImageRejectReason.InternalError: | ||
| throw new Error('Internal error, falling back to a redirect'); | ||
| default: | ||
| throw new Error( | ||
| `Unknown reject reason "${rejectReason}", falling back to a redirect` | ||
| ); |
There was a problem hiding this comment.
The "original images" here are on the files.gitbook.com domain or another one?
The main risk of serving just anything on the current domain is that it causes issues with access to domain's private data (especially cookies, etc...). If redirecting to files.gitbook.com is the fallback, it could remain bad IMO because that could leak data from on main app's domain too.
We should just make sure where the images are served, and maybe in this case we could/should serve images on yet another, isolated domain.
Enhance image processing by adding support for image signature version 3, and refining error handling in image resizing logic. Improve options and accept header handling for resizing functionality.