Wiki webhook `absolute_image_urls` does not work properly
Summary
When a project wiki webhook is triggered with an uploaded image URL inside the description, the sent payload does not contain the proper absolute image URL.
Steps to reproduce
- Create a project webhook: [Go to your project] > Settings > Webhooks > Add new webhook > tick "Wiki page events"
- Create or edit a project wiki: [Go to your project] > Plan > Wiki
- Upload an image to the description
- Click "Create Page"
- Check the sent payload on your configured server on point 1
What is the current bug behavior?
Example of my private GitLab project:
{
...(omitted)...
"object_attributes": {
"content": "test image\r\n\r\n![Screenshot_2024-03-08_at_08.52.54](https://gitlab.com/uploads/b25a2d32924977205d45754ca6357c9b/Screenshot_2024-03-08_at_08.52.54.png)",
"format": "markdown",
"message": "Create home image",
"title": "home image",
"slug": "home-image",
"url": "https://gitlab.com/ivantedja/blessing/-/wikis/home-image",
"action": "create",
"diff_url": "https://gitlab.com/ivantedja/blessing/-/wikis/home-image/diff?version_id=b6a496243b6498221ace381da68667002414ad29"
}
}
Notice the incorrect absolute image URL: https://gitlab.com/uploads/b25a2d32924977205d45754ca6357c9b/Screenshot_2024-03-08_at_08.52.54.png
The correct one is supposed to be: https://gitlab.com/ivantedja/blessing/-/wikis/uploads/b25a2d32924977205d45754ca6357c9b/Screenshot_2024-03-08_at_08.52.54.png
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
Under the hood, the wiki webhook calls absolute_image_urls
in https://gitlab.com/gitlab-org/gitlab/-/blob/68f07f7234a8bd912e5a371aa473881dd9f8f54e/lib/gitlab/hook_data/wiki_page_builder.rb#L12
The issues:
- The image URL does not match this conditional: https://gitlab.com/gitlab-org/gitlab/-/blob/68f07f7234a8bd912e5a371aa473881dd9f8f54e/lib/gitlab/hook_data/base_builder.rb#L45
- I'm not sure how it happens historically, but the uploaded image in the wiki has "markdown format"
![](uploads/...)
instead of![](/uploads/...)
- I'm not sure how it happens historically, but the uploaded image in the wiki has "markdown format"
- Even if it reaches the code in point 1, the generated image URL is still not correct as it needs
/-/wikis
in the URL. Probably, we can usewiki_page.wiki.wiki_base_path
in https://gitlab.com/gitlab-org/gitlab/-/blob/68f07f7234a8bd912e5a371aa473881dd9f8f54e/lib/gitlab/hook_data/wiki_page_builder.rb#L17