Skip to content

Commit b811c7c

Browse files
author
aleixgilaguilar
committed
PR corrections. Use of strip_tags().
1 parent 3ecf59b commit b811c7c

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

app/Http/Controllers/Api/CommentsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class CommentsController extends ApiController
99
{
1010
public function store(Ticket $ticket)
1111
{
12-
$comment = $ticket->addComment(null, sanitizeJSInjection(request('body')), request('new_status'));
12+
$comment = $ticket->addComment(null, strip_tags(request('body')), request('new_status'));
1313
if (! $comment) {
1414
return $this->respond(['id' => null, 'message' => 'Can not create a comment with empty body'], Response::HTTP_OK);
1515
}

app/Http/Controllers/Api/TicketsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function store()
3838

3939
$ticket = Ticket::createAndNotify(
4040
request('requester'),
41-
sanitizeJSInjection(request('title')),
42-
sanitizeJSInjection(request('body')),
41+
strip_tags(request('title')),
42+
strip_tags(request('body')),
4343
request('tags')
4444
);
4545

helpers/helpers.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,3 @@ function toPercentage($value, $inverse = false)
5555
{
5656
return ($inverse ? 1 - $value : $value) * 100;
5757
}
58-
59-
function sanitizeJSInjection($text)
60-
{
61-
return str_replace('/script>', '/\script>', str_replace('<script', '<\script', $text));
62-
}

tests/Feature/Api/SimpleTicketTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function can_create_a_ticket_with_js_injection(){
9292
"name" => "johndoe",
9393
"email" => "[email protected]"
9494
],
95-
"title" => "App <script>is not working</script>",
95+
"title" => "App <script>is not working</script> >>>",
9696
"body" => "I can't log in into the application<script>alert(1)</script>",
9797
"tags" => ["xef"]
9898
],["token" => 'the-api-token']);
@@ -106,8 +106,8 @@ public function can_create_a_ticket_with_js_injection(){
106106
$this->assertEquals($requester->email, "[email protected]");
107107
$this->assertEquals( $ticket->requester_id, $requester->id);
108108
});
109-
$this->assertEquals ( $ticket->title, "App <\script>is not working</\script>");
110-
$this->assertEquals ( $ticket->body, "I can't log in into the application<\script>alert(1)</\script>");
109+
$this->assertEquals ( $ticket->title, "App is not working >>>");
110+
$this->assertEquals ( $ticket->body, "I can't log in into the applicationalert(1)");
111111
$this->assertTrue ( $ticket->tags->pluck('name')->contains("xef") );
112112
$this->assertEquals( Ticket::STATUS_NEW, $ticket->status);
113113

@@ -222,7 +222,7 @@ public function requester_can_comment_the_ticket_with_js_injection(){
222222
$response->assertJson (["data" => ["id" => 2]]);
223223

224224
$this->assertCount (2, $ticket->comments);
225-
$this->assertEquals ($ticket->comments[1]->body, "<\script> this is a comment </\script>");
225+
$this->assertEquals ($ticket->comments[1]->body, " this is a comment ");
226226

227227
//TODO: assert notifications
228228
}

0 commit comments

Comments
 (0)