Skip to content

chore: sécuriser le rendu des URLs externes et supprimer l’ignore Brakeman XSS#508

Open
yann120 wants to merge 6 commits intomainfrom
chore/fix_xss_vulnerability
Open

chore: sécuriser le rendu des URLs externes et supprimer l’ignore Brakeman XSS#508
yann120 wants to merge 6 commits intomainfrom
chore/fix_xss_vulnerability

Conversation

@yann120
Copy link
Copy Markdown
Collaborator

@yann120 yann120 commented Apr 2, 2026

Cette PR corrige l’alerte XSS Brakeman sur le rendu de site.url.

Elle:

  • centralise la validation des URLs externes dans Link
  • empêche le rendu de liens non sûrs dans les vues des sites
  • supprime le html_safe inutile dans le message de redirection
  • retire l’ignore Brakeman XSS devenu obsolète
  • ajoute les tests associés

Vérification:

  • bundle exec brakeman -q ne remonte plus de warning XSS

@yann120 yann120 self-assigned this Apr 2, 2026
@sentry-sentry-incubateur-net
Copy link
Copy Markdown

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: app/models/link.rb

Function Unhandled Issue
Link.parse Link::InvalidUriError: Addressable::URI cannot parse 'http://' (Link::InvalidUriError) ...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@yann120 yann120 added the chore Technical task label Apr 2, 2026
@yann120 yann120 linked an issue Apr 2, 2026 that may be closed by this pull request
@yann120 yann120 force-pushed the chore/fix_xss_vulnerability branch from ed0816b to ce3a5e2 Compare April 2, 2026 15:33
Comment thread app/views/checks/_reachable.html.erb
Comment thread app/views/sites/_site.html.erb Outdated
<td class="fr-cell--center"><%= link_icon(:article, t('.view_name', name: site.name_with_fallback), url_for([site, site.audit]), title: t('.view_name', name: site.name_with_fallback), line: true, side: :left, sr_only: true) %></td>
<td><%= link_to site.url_without_scheme_and_www.truncate(35, separator: /\W/), site.url, target: :_blank, title: site.url_without_scheme_and_www.length > 35 ? site.url_without_scheme_and_www : nil %></td>
<% display_url = site.url_without_scheme_and_www %>
<% truncated_url = display_url.truncate(35, separator: /\W/) %>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Est‑ce qu’on veut mettre ce 35 dans une constante globale ?
Je ne sais pas si on réutiliserait cela pour ne pas avoir d’URL trop longues à afficher.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On l'utilise à plusieurs endroit donc oui !

Comment thread config/locales/fr.yml
Comment thread spec/requests/sites_controller_spec.rb Outdated
end

context "when a stored site URL is unsafe" do
let(:unsafe_url) { "ftp://example.com" }
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ici, je voulais injecter du JavaScript, mais c'est impossible.

Alors, une page FTP pour le test contourne le problème, même si, en effet, ce n'est pas une injection XSS.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tu testes 3 fois cette fonctionnalité déjà. Ici on a pas à tester le sites controller, tu as changé le url validator, c'est audit model que tu veux tester ou url validator (qui d'ailleurs n'a pas à être ce qu'il est et serait un très bon sujet de scouting (🙄)).
On peut en parler en direct, ça sera plus simple.

@yann120 yann120 marked this pull request as ready for review April 2, 2026 15:42
@yann120 yann120 requested a review from Josyann April 2, 2026 15:42
Comment thread app/models/link.rb Outdated
return if href.blank?

uri = parse(href)
uri.to_s if uri.host.present? && uri.scheme&.match?(/\Ahttps?\z/)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
uri.to_s if uri.host.present? && uri.scheme&.match?(/\Ahttps?\z/)
uri.to_s if uri.host.present? && uri.scheme&.in?(%w[http https])

Comment thread app/views/checks/_reachable.html.erb
Comment thread spec/requests/sites_controller_spec.rb Outdated
end

context "when a stored site URL is unsafe" do
let(:unsafe_url) { "ftp://example.com" }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tu testes 3 fois cette fonctionnalité déjà. Ici on a pas à tester le sites controller, tu as changé le url validator, c'est audit model que tu veux tester ou url validator (qui d'ailleurs n'a pas à être ce qu'il est et serait un très bon sujet de scouting (🙄)).
On peut en parler en direct, ça sera plus simple.

Comment thread app/views/sites/_site.html.erb Outdated
<td class="fr-cell--center"><%= link_icon(:article, t('.view_name', name: site.name_with_fallback), url_for([site, site.audit]), title: t('.view_name', name: site.name_with_fallback), line: true, side: :left, sr_only: true) %></td>
<td><%= link_to site.url_without_scheme_and_www.truncate(35, separator: /\W/), site.url, target: :_blank, title: site.url_without_scheme_and_www.length > 35 ? site.url_without_scheme_and_www : nil %></td>
<% display_url = site.url_without_scheme_and_www %>
<% truncated_url = display_url.truncate(35, separator: /\W/) %>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On l'utilise à plusieurs endroit donc oui !

@yann120 yann120 force-pushed the chore/fix_xss_vulnerability branch from 7d861a6 to 1451d20 Compare April 20, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Technical task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CHORE] 🚨 STOP ignoring brakeman alerts 🚨

2 participants