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

fix(web): handle trailing slash in external domain #6253

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

danieldietzler
Copy link
Member

Addresses #6146 (comment)

Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2ae48df
Status: ✅  Deploy successful!
Preview URL: https://4c4cda51.immich.pages.dev
Branch Preview URL: https://fix-sanitize-external-domain.immich.pages.dev

View logs

Comment on lines +23 to +24
const url = externalDomain || window.location.origin;
return `${url + url.endsWith('/') ? '' : '/'}share/${key}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use a URL constructor instead? I believe this should work (untested):

Suggested change
const url = externalDomain || window.location.origin;
return `${url + url.endsWith('/') ? '' : '/'}share/${key}`;
const base = externalDomain || window.location.origin;
return new URL(`/share/${key}`, base).href;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's very well possible. I only did a quick google search (less than 1 minute lol) and people were like "yea, regex" lol
I'll test it real quick

Copy link
Member Author

@danieldietzler danieldietzler Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this doesn't work if your domain has a path as well (so immich.app/public/). Not sure if that's common though...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, though at the moment it's not possible to run Immich under a path anyways.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't tested with it and I think there are some things that don't work with it like goto(/photos)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that there are absolute paths but I was thinking you could have proxy rewrite rules for that stuff. Or well, at that point, you could also redirect /share to /public/share, nvm lol

@zackpollard
Copy link
Contributor

I'm wondering if it would be better to just validate this in the config, rather than have to correct for it later

@danieldietzler
Copy link
Member Author

I'm wondering if it would be better to just validate this in the config, rather than have to correct for it later

I was thinking about that as well. Basically you have three options:

  1. validate server-side and don't accept "invalid" domains
  2. sanitize server-side and store the sanitized value
  3. do what I did

IMO 2) is kinda ugly because then you save something and on reload there is something else. That's confusing. And 1) could be annoying I think because technically it's not wrong and I personally hate it when I get errors that shouldn't be errors and only happen because the software is too stupid to handle those lmao

Copy link
Contributor

@jrasm91 jrasm91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jrasm91
Copy link
Contributor

jrasm91 commented Jan 8, 2024

I went through this same mental exercise and I think this solution works well enough.

@alextran1502 alextran1502 merged commit 8d0a619 into main Jan 9, 2024
20 of 21 checks passed
@alextran1502 alextran1502 deleted the fix/sanitize-external-domain branch January 9, 2024 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants