Comments (5)
Hi @ericdeansanchez,
Sorry for the lack of clarity in the original question, an example would have helped.
Yes, that's exactly the situation.
from js-core.
Hey @fredshevek - Fred from imgix here 👋 We talked about this a bit internally and I came up with a crazy idea that we want to share with you.
- Create an imgix webproxy source (e.g
fredshevekapi.imgix.com
) which points TO the server where you are running this code, e.g.https://fredshevekapi.netlify.com/image-api/
. - When creating imgix urls with encrypted API keys; instead of creating imgix webproxy urls with the embedded api key, encrypt the original url using a private key, and create an imgix webproxy url to the server itself with the imgix domain and this encrypted url.
e.g. the original urlhttps://proxydomain.com/image.png?key=123
is encrypted to928nriorsotne
. It is then added to an imgix webproxy urlfredshevekapi.imgix.net
and the resulting image URL ishttps://fredshevekapi.imgix.net/928nriorsotne
.
In JS:
const KEY = 'super_secret_private_key';
const url = 'https://proxydomain.com/image.png?key=123`
const encryptedUrl = encrypt(url, KEY)
const ub = new ImgixClient({domain: 'fredshevekapi.imgix.net', secureUrlToken: 'abc'});
const imageUrl = ub.buildURL(encryptedUrl) // pass this to the client.
// this will create an image url like this: https://fredshevekapi.imgix.net/928nriorsotne
- Then, the browser will request this “image” from imgix at https://fredshevekapi.imgix.net/928nriorsotne.
- Because of the webproxy, imgix will go back to the same server as in (2) to request this “image”, in this case: https://fredshevekapi.netlifty.com/image-api/928nriorsotne
- The same server should then decrypt the “image key” into the original image URL and do a 302 redirect (imgix follows redirects).
In JS:
app.get('/image-api/:encryptedUrl', (request, response) => {
const encryptedUrl = request.params.encryptedUrl;
if (!encryptedUrl) {
response.status(404)
}
const decryptedUrl = decrypt(encryptedUrl, KEY); // same key as in (1)
response.redirect(decryptedUrl)
})
- imgix sees this as a normal image (and has no idea what happened behind the scenes)
- image is rendered on the browser and bob’s your uncle
Although this is quite a complicated solution/suggestion, I think it is within the realms of reasonably complexity if executed correctly. For instance, if the server fails to respond in (5), imgix will just retry at a later time. In terms of performance, the initial image request might take slightly longer due to the extra request step of (5) compared to a "normal" request, every request after this will be cached. imgix also has an origin cache so that the image doesn't have to be refetched when imgix parameters change.
Another option
This could also be stripped down to not have the encryption, and instead of passing around the encrypted url, it could just pass around the image url to proxy without the api key, and then the server could add the api key back in (4). i.e in (2) the server creates an image url of https://fredshevekapi.imgix.net/image.png, and then in (5) the script should add the api key ?key=123
to the image request.
Let me know what you think and if either of these options work out for you!
from js-core.
Hey @fredshevek 👋 thanks for opening this issue! Could you clarify what you mean by your API_KEY
being left "in the open?"
Is this your situation?
var ub = new ImgixClient({domain: 'domain.imgix.net', secureUrlToken: 'abc'});
var url = ub.buildURL('https://proxydomain.com/image.png?key=123');
console.log(url);
// https://domain.imgix.net/https%3A%2F%2Fproxydomain.com%2Fimage.png%3Fkey=123?s=...'
from js-core.
Those options make sense. In fact, I'm already on Netlify, so I can do this with a Netlify Function easily.
I think adding the API key on Netlify and dropping encryption all together is the best option.
Thanks a lot for following this up!
from js-core.
Great, glad we could help @fredshevek! I'm going to mark this is as closed for not as I think we've progressed far enough on the original question, but let us know how it goes and if you have any more questions!
from js-core.
Related Issues (20)
- `buildSrcSet` mutates `params` argument when building either fluid or fixed-width srcset. HOT 2
- A fluid-width srcset is generated when a height is passed HOT 13
- Image has distored boarder when used in <meta></meta> tag HOT 1
- Expires params? HOT 2
- Action Required: Fix Renovate Configuration
- Dependency Dashboard
- Allow different Quality presets for buildSrcSet HOT 3
- Allow configure srcSet DPR generation HOT 3
- Relax js-base64 constraint to `^3.6` HOT 2
- Typescript types for `params` HOT 3
- Do you support Management APIs? HOT 3
- Could you also allow localhost:${port} in DOMAIN_REGEX? HOT 5
- Query parameter values should be URL encoded HOT 10
- Latest @imgix/js-core does not work with Nuxt 3 HOT 4
- host is depracated but... HOT 4
- Ability to define success/failure/processing handlers HOT 1
- Typings HOT 10
- Typescript and `@types/node` should be devDependencies. HOT 2
- Plus-sign in S3 key causes 404 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-core.