Skip to content

Commit

Permalink
fix: sanitize project/org name in invitation emails (#1898)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyynthia committed Sep 6, 2023
1 parent 37b96d0 commit bab718b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ class OrganizationControllerInvitingTest : AuthorizedControllerTest() {
emailTestUtil.assertEmailTo.isEqualTo(INVITED_EMAIL)
}

@Test
fun `e-mail is sanitized`() {
dummyDto.name = "Test org <a href='https://evil.local'>test</a>"
val organization = prepareTestOrganization()

inviteWithUserWithNameAndEmail(organization.id)
emailTestUtil.verifyEmailSent()

val messageContent = emailTestUtil.messageContents.single()
assertThat(messageContent).doesNotContain("<a href='https://evil.local")
assertThat(messageContent).contains("&lt;a href=&#39;https://evil.local")
}

@Test
fun `does not invite when email already invited`() {
val organization = prepareTestOrganization()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.tolgee.component.FrontendUrlProvider
import io.tolgee.dtos.misc.EmailParams
import io.tolgee.model.Invitation
import org.springframework.stereotype.Component
import org.springframework.web.util.HtmlUtils

@Component
class InvitationEmailSender(
Expand Down Expand Up @@ -45,8 +46,10 @@ class InvitationEmailSender(
}

val name = projectNameOrNull ?: organizationNameOrNull
?: throw IllegalStateException("Both the organization and the project are null??")

return "You have been invited to $toWhat $name in Tolgee."
val escapedName = HtmlUtils.htmlEscape(name)
return "You have been invited to $toWhat $escapedName in Tolgee."
}

private fun getInvitationAcceptUrl(code: String): String {
Expand Down

0 comments on commit bab718b

Please sign in to comment.