File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44class MonAvisEmbedValidator < ActiveModel ::Validator
55 # from time to time, they decide to change domain just for fun. if it breaks, check the new subdomain
66 KNOWN_SUBDOMAIN = [ 'jedonnemonavis' , 'monavis' , 'voxusagers' ]
7- HREF_CHECKER = /https:\/ \/ #{ KNOWN_SUBDOMAIN . join ( '|' ) } .numerique.gouv.fr\/ Demarches\/ \d +.*key=[[:alnum:]]+.*/
8- IMG_CHECKER = /https:\/ \/ #{ KNOWN_SUBDOMAIN . join ( '|' ) } .numerique.gouv.fr\/ (monavis-)?static\/ bouton-blanc|bleu. png|svg/
7+ HREF_CHECKER = /https:\/ \/ (?: #{ KNOWN_SUBDOMAIN . join ( '|' ) } ) .numerique.gouv.fr\/ Demarches\/ \d +.*key=[[:alnum:]]+.*/
8+ IMG_CHECKER = /https:\/ \/ (?: #{ KNOWN_SUBDOMAIN . join ( '|' ) } ) .numerique.gouv.fr\/ (monavis-)?static\/ bouton-(?: blanc|bleu).(?: png|svg) /
99
1010 ALLOWED_TAGS = %w[ a img ] . freeze
1111 ALLOWED_ATTRIBUTES = %w[ href src alt title target rel ] . freeze
Original file line number Diff line number Diff line change 422422 </a>
423423 MSG
424424 let ( :procedure ) { build ( :procedure , monavis_embed : monavis_jedonnemonavis ) }
425- it { is_expected . to eq ( [ "Le code MonAvis contient un lien pointant vers un domaine invalide" ] ) }
425+ it { is_expected . to include ( "Le code MonAvis contient un lien pointant vers un domaine invalide" ) }
426+ end
427+
428+ context 'rejects a link to an arbitrary domain containing monavis as a substring (regex bypass)' do
429+ malicious_embed = <<-MSG
430+ <a href="https://evil.com/phishing?ref=monavis&nd_source=button&key=abc123">
431+ <img src="https://monavis.numerique.gouv.fr/monavis-static/bouton-bleu.png" alt="avis" />
432+ </a>
433+ MSG
434+ let ( :procedure ) { build ( :procedure , monavis_embed : malicious_embed ) }
435+ it { is_expected . to be_present }
426436 end
427437
428438 context 'when YWH-PGM5381-46 pentester won' do
You can’t perform that action at this time.
0 commit comments