Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse first, then interpolate #1345

Merged
merged 2 commits into from
Jul 16, 2021
Merged

parse first, then interpolate #1345

merged 2 commits into from
Jul 16, 2021

Conversation

ckruse
Copy link
Contributor

@ckruse ckruse commented Jul 15, 2021

This avoids problems with user given values potentially breaking the parse tree

Regarding #1344

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • documentation is changed or added

This avoids problems with user given values potentially breaking the parse tree

Regarding #1344
@coveralls
Copy link

coveralls commented Jul 15, 2021

Coverage Status

Coverage decreased (-0.2%) to 96.416% when pulling c1e4f07 on ckruse:master into 23b5481 on i18next:master.

@ckruse ckruse marked this pull request as ready for review July 16, 2021 05:24
@ckruse
Copy link
Contributor Author

ckruse commented Jul 16, 2021

I believe this is ready for review

@adrai
Copy link
Member

adrai commented Jul 16, 2021

lgtm

@adrai adrai requested a review from jamuhl July 16, 2021 05:41
@adrai adrai changed the title WIP: parse first, then interpolate parse first, then interpolate Jul 16, 2021
@adrai
Copy link
Member

adrai commented Jul 16, 2021

should be still backwards compatible, right?
So patch or minor version is sufficient?

@jamuhl
Copy link
Member

jamuhl commented Jul 16, 2021

lgtm.... https://github.com/i18next/react-i18next/blob/master/test/trans.render.spec.js#L336 -> initial reason should be covered by tests

@adrai adrai merged commit 498b441 into i18next:master Jul 16, 2021
@adrai
Copy link
Member

adrai commented Jul 16, 2021

included in v11.11.3

@adrai
Copy link
Member

adrai commented Jul 16, 2021

Thank you @ckruse for your contribution.

@ckruse
Copy link
Contributor Author

ckruse commented Jul 16, 2021

Thank you for your work!

@dlavrenuek
Copy link

I wanted to create an issue but since this was fixed in this PR I would like to comment with some additional information. The Trans component in react-i18next < 11.11.3 is vulnerable to XSS attacks because the provided variables were rendered as HTML. Example code:

function App() {
    const [text, setText] = useState('');

    return (
        <>
            <input
                value={text}
                onChange={(e) => setText(e.target.value)}
            />
            <p><Trans>You entered {{text}}</Trans></p>
        </>
    );
}

@dlavrenuek
Copy link

@jamuhl @adrai According to https://nodejs.org/en/security/#reporting-a-bug-in-a-third-party-module a package owner should create a security report, so the vulnerability is properly reported by npm vulnerability check and tools like dependabot.

@adrai
Copy link
Member

adrai commented Aug 2, 2021

@dlavrenuek
with react-i18next v11.0.0 - v11.11.4 it's always the same:
input: my <b>variable</b> <div>and other</div>
output: <p>You entered my &lt;b&gt;variable&lt;/b&gt; &lt;div&gt;and other&lt;/div&gt;</p>

Maybe you compared it to a version < v10.12.2 ? => https://github.com/i18next/react-i18next/blob/master/CHANGELOG.md#10122 (342027d)

@dlavrenuek
Copy link

@adrai I missed to provide that Trans was only vulnerable to XSS when setting the option escapeValue to true which is suggested as default by https://react.i18next.com/guides/quick-start#configure-i-18-next

interpolation: {
    escapeValue: true
}

So far I was not successful at executing javascript with it due to restrictions with transKeepBasicHtmlNodesFor, but you can destroy the page layout by adding a lot of <br /> and <p> and may be exploit it in some way.

@jamuhl
Copy link
Member

jamuhl commented Aug 2, 2021

escapeValue is suggested to be set to false -> as react already escapes strings rendered in elements.

this was tested long ago and there is yet no known way of injecting executable code into Trans - but we're happy to be proven wrong

As the transKeepBasicHtmlNodesFor come from your translation I guess that is save

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants