-
-
Notifications
You must be signed in to change notification settings - Fork 127
fix(photos): preserve source page after photo deletion #1777
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,10 +410,34 @@ public function renderDeletePhoto(int $ownerId, int $photoId): void | |
| $this->flashFail("err", tr("error_access_denied_short"), tr("error_access_denied")); | ||
| } | ||
|
|
||
| if (!is_null($album = $photo->getAlbum())) { | ||
| $redirect = null; | ||
| $returnTo = $this->queryParam("return_to"); | ||
|
|
||
| if (is_string($returnTo) && $returnTo !== "") { | ||
| $parsedReturnTo = parse_url($returnTo); | ||
| if ($parsedReturnTo !== false && !isset($parsedReturnTo["host"]) && str_starts_with($returnTo, "/") && !str_starts_with($returnTo, "//")) { | ||
| $redirect = $returnTo; | ||
| } elseif ($parsedReturnTo !== false && isset($parsedReturnTo["host"])) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. по сути оно делает то же самое - берет сугубо для простоты я считаю можно просто разрешать только безопасные относительные пути без протоколов и доменов к примеру: if (
is_string($returnTo)
&& str_starts_with($returnTo, "/")
&& !str_starts_with($returnTo, "//")
&& !str_starts_with($returnTo, "/\\")
) {
$parsed = parse_url($returnTo);
if ($parsed !== false && !isset($parsed["scheme"]) && !isset($parsed["host"])) {
$redirect =$returnTo;
}
} |
||
| $currentHost = strtolower((string) ($_SERVER["HTTP_HOST"] ?? "")); | ||
| $returnHost = strtolower($parsedReturnTo["host"] . (isset($parsedReturnTo["port"]) ? ":" . $parsedReturnTo["port"] : "")); | ||
| if ($currentHost !== "" && $returnHost === $currentHost) { | ||
| $redirect = $parsedReturnTo["path"] ?? "/"; | ||
| if (isset($parsedReturnTo["query"])) { | ||
| $redirect .= "?" . $parsedReturnTo["query"]; | ||
| } | ||
| if (isset($parsedReturnTo["fragment"])) { | ||
| $redirect .= "#" . $parsedReturnTo["fragment"]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($redirect === null && !is_null($album = $photo->getAlbum())) { | ||
| $redirect = '/album' . $album->getPrettyId(); | ||
| } else { | ||
| $redirect = "/id0"; | ||
| } | ||
|
|
||
| if ($redirect === null) { | ||
| $redirect = $photo->getOwner()->getURL(); | ||
| } | ||
|
|
||
| $photo->isolate(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ | |
| </a> | ||
| <div n:if="isset($thisUser) && $thisUser->getId() === $photo->getOwner()->getId()"> | ||
| <a href="/photo{$photo->getPrettyId()}/edit" class="profile_link" style="display:block;width:96%;">{_edit}</a> | ||
| <a id="_photoDelete" href="/photo{$photo->getPrettyId()}/delete" class="profile_link" style="display:block;width:96%;">{_delete}</a> | ||
| <a id="_photoDelete" href="/photo{$photo->getPrettyId()}/delete{ifset $_SERVER['HTTP_REFERER']}?return_to={rawurlencode($_SERVER['HTTP_REFERER'])}{/ifset}" class="profile_link" style="display:block;width:96%;">{_delete}</a> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. реферер может содержать чисто в теории что-то лишнее (внешний сайт условно говоря), и ссылка в шаблоне может тогда содержать лишний мусор мне кажется реферер можно определять прямо в PhotosPresenter через $this->getHttpRequest()->getReferer() как fallback если мы не передали return_to |
||
| </div> | ||
| <a href="{$photo->getURL()}" class="profile_link" target="_blank" style="display:block;width:96%;">{_"open_original"}</a> | ||
| <a n:if="isset($thisUser) && $thisUser->getId() != $photo->getOwner()->getId()" class="profile_link" style="display:block;width:96%;" href="javascript:reportPhoto({$photo->getId()})">{_report}</a> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я бы предпочел брать путь более строгим путем или проверять регуляркой типа:
!str_starts_with($returnTo, '//') && !str_starts_with($returnTo, '/\\')насколько я помню parse_url в PHP в некоторых случаях работает не всегда точно
то есть, грубо говоря, я бы добавил еще проверку на
!str_starts_with($returnTo, "/\\")