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

FIX with-apollo-auth example token access #4771

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions examples/with-apollo-auth/lib/withApollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export default App => {

static async getInitialProps(ctx) {
const { Component, router, ctx: { req, res } } = ctx
const token = parseCookies(req).token
const apollo = initApollo({}, {
getToken: () => parseCookies(req).token
getToken: () => token
})

ctx.ctx.apolloClient = apollo
Expand Down Expand Up @@ -69,7 +70,8 @@ export default App => {

return {
...appProps,
apolloState
apolloState,
token
Copy link
Member

@timneutkens timneutkens Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially dangerous as passing down the cookie means you're taking input from the user and returning it to them, which, if Next.js didn't htmlescape the getInitialProps result, would lead to an XSS vulnerability.

To be clear Next.js does htmlescape the getInitialProps result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, do cookies have a similar behavior maybe in a lower level? Cookies travel in the headers to the both ways. Does this represent an XSS vulnerability too?

}
}

Expand All @@ -78,7 +80,7 @@ export default App => {
// `getDataFromTree` renders the component first, the client is passed off as a property.
// After that rendering is done using Next's normal rendering pipeline
this.apolloClient = initApollo(props.apolloState, {
getToken: () => parseCookies().token
getToken: () => props.token
})
}

Expand Down