Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Commit

Permalink
Don't escape label contents
Browse files Browse the repository at this point in the history
Trying to protect against XSS in the case that someone is using
user input for label contents is not worth the trade-off of disallowing
users of the library to customize the HTML contents of their labels.

If you are using user input in your labels, I recommend escaping
that data manually before including it in your label.
  • Loading branch information
adamwathan committed Jul 7, 2017
1 parent 5000dcf commit d44534b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/AdamWathan/Form/Elements/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public function render()
$tags = [sprintf('<label%s>', $this->renderAttributes())];

if ($this->labelBefore) {
$tags[] = $this->escape($this->label);
$tags[] = $this->label;
}

$tags[] = $this->renderElement();

if (! $this->labelBefore) {
$tags[] = $this->escape($this->label);
$tags[] = $this->label;
}

$tags[] = '</label>';
Expand Down
8 changes: 0 additions & 8 deletions tests/LabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,4 @@ public function testCanRetrieveElement()
$result = $label->after($element)->getControl();
$this->assertEquals($element, $result);
}

public function testAgainstXssAttacksInLabel()
{
$label = new Label('<script>alert("xss")</script>');
$expected = '<label>&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;</label>';
$result = $label->render();
$this->assertEquals($expected, $result);
}
}

0 comments on commit d44534b

Please sign in to comment.