123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- require 'test_helper'
- class TicketXssTest < ActiveSupport::TestCase
- test 'xss via model' do
- ticket = Ticket.create(
- title: 'test 123 <script type="text/javascript">alert("XSS!");</script>',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert(ticket, 'ticket created')
- assert_equal('test 123 <script type="text/javascript">alert("XSS!");</script>', ticket.title, 'ticket.title verify')
- assert_equal('Users', ticket.group.name, 'ticket.group verify')
- assert_equal('new', ticket.state.name, 'ticket.state verify')
- article1 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: '<script type="text/javascript">alert("XSS!");</script>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal('alert("XSS!");', article1.body, 'article1.body verify - inbound')
- article2 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: 'please tell me this doesn\'t work: <script type="text/javascript">alert("XSS!");</script>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal('please tell me this doesn\'t work: alert("XSS!");', article2.body, 'article2.body verify - inbound')
- article3 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: 'please tell me this doesn\'t work: <table>ada<tr></tr></table><div class="adasd" id="123" data-abc="123"></div><div><a href="javascript:someFunction()">LINK</a><a href="http://lalal.de">aa</a><some_not_existing>ABC</some_not_existing>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal("please tell me this doesn't work: <table>ada<tr></tr>
- </table><div></div><div>
- LINK<a href=\"http://lalal.de\" rel=\"nofollow noreferrer noopener\" target=\"_blank\" title=\"http://lalal.de\">aa</a>ABC</div>", article3.body, 'article3.body verify - inbound')
- article4 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: 'please tell me this doesn\'t work: <video>some video</video><foo>alal</foo>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal("please tell me this doesn't work: <video>some video</video>alal", article4.body, 'article4.body verify - inbound')
- article5 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/plain',
- body: 'please tell me this doesn\'t work: <table>ada<tr></tr></table><div class="adasd" id="123" data-signature-id="123"></div><div><a href="javascript:someFunction()">LINK</a><a href="http://lalal.de">aa</a><some_not_existing>ABC</some_not_existing>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal('please tell me this doesn\'t work: <table>ada<tr></tr></table><div class="adasd" id="123" data-signature-id="123"></div><div><a href="javascript:someFunction()">LINK</a><a href="http://lalal.de">aa</a><some_not_existing>ABC</some_not_existing>', article5.body, 'article5.body verify - inbound')
- article6 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: 'some message article helper test1 <div><img style="width: 85.5px; height: 49.5px" src="cid:15.274327094.140938@zammad.example.com">asdasd<img src="cid:15.274327094.140939@zammad.example.com"><br>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal('some message article helper test1 <div>
- <img style="width: 85.5px; height: 49.5px;" src="cid:15.274327094.140938@zammad.example.com">asdasd<img src="cid:15.274327094.140939@zammad.example.com"><br>
- </div>', article6.body, 'article6.body verify - inbound')
- article7 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: 'some message article helper test1 <div><img style="width: 85.5px; height: 49.5px" src="api/v1/ticket_attachment/123/123/123">asdasd<img src="api/v1/ticket_attachment/123/123/123"><br>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal('some message article helper test1 <div>
- <img style="width: 85.5px; height: 49.5px;" src="api/v1/ticket_attachment/123/123/123">asdasd<img src="api/v1/ticket_attachment/123/123/123"><br>
- </div>', article7.body, 'article7.body verify - inbound')
- article8 = Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject <script type="text/javascript">alert("XSS!");</script>',
- message_id: 'some@id',
- content_type: 'text/html',
- body: 'some message article helper test1 <a href="#" onclick="some_function();">abc</a> <a href="https://example.com" oNclIck="some_function();">123</a><body>123</body>',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_equal('some message article helper test1 <a href="#">abc</a> <a href="https://example.com" rel="nofollow noreferrer noopener" target="_blank" title="https://example.com">123</a>123', article8.body, 'article8.body verify - inbound')
- end
- test 'xss via mail' do
- data = 'From: ME Bob <me@example.com>
- To: customer@example.com
- Subject: some subject
- Content-Type: text/html
- MIME-Version: 1.0
- no HTML <script type="text/javascript">alert(\'XSS\')</script>'
- parser = Channel::EmailParser.new
- ticket, article, user = parser.process({}, data)
- assert_equal('text/html', ticket.articles.first.content_type)
- assert_equal('no HTML alert(\'XSS\')', ticket.articles.first.body)
- data = 'From: ME Bob <me@example.com>
- To: customer@example.com
- Subject: some subject
- Content-Type: text/plain
- MIME-Version: 1.0
- no HTML <script type="text/javascript">alert(\'XSS\')</script>'
- parser = Channel::EmailParser.new
- ticket, article, user = parser.process({}, data)
- assert_equal('text/plain', ticket.articles.first.content_type)
- assert_equal('no HTML <script type="text/javascript">alert(\'XSS\')</script>', ticket.articles.first.body)
- end
- end
|