You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- update aspnet-prerendering package from 1.0.x to latest 3.0.1
- fixed code that breaks after using aspnet-prerendering 3.0.1
- added a section about XSS
- updated renderOnServer.js with XSS prevention code
Copy file name to clipboardExpand all lines: README.md
+50-2Lines changed: 50 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@ To simulate timely API call form remote server, we add the following line in Hom
99
99
- webpack-merge
100
100
- dependencies:
101
101
- vue-server-renderer
102
-
- aspnet-prerenderer*(Note that only version ^1.0.0 is supported, using latest ^3.0.0+ will break the code.)*
102
+
- aspnet-prerenderer
103
103
104
104
2. Split the code into two part:
105
105
@@ -130,4 +130,52 @@ Using Bootstrap in VueJS application is easy with BootstrapVue:
130
130
- Import the css files: (tricky here, for this repo I need to add the imports at client.js instead of app.js)
131
131
import 'bootstrap/dist/css/bootstrap.css'
132
132
import 'boostrap-vue/dist/bootstrap-vue.css'
133
-
- Add the Bootstrap components (e.g. I added a badge at Dashboard.vue template.)
133
+
- Add the Bootstrap components (e.g. I added a badge at Dashboard.vue template.)
134
+
135
+
### Prevent XSS Attack:
136
+
During the jounary in solveing the asp-prerendering v3.0.0+ dependency issue, I found an article talking about Cross-site scripting attack in JavaScript applications: *[The Most Common XSS Vulnerability in React.js Applications](https://medium.com/node-security/the-most-common-xss-vulnerability-in-react-js-applications-2bdffbcc1fa0)* And turns out rednerOnServer.js also has such vulnerability.
xss:"</script><script>alert('Possible XSS vulnerability from user input!')</script>"
144
+
}
145
+
resolve({
146
+
globals: {
147
+
__INITIAL_STATE__: context
148
+
}
149
+
})
150
+
})
151
+
});
152
+
153
+
If we modify the renderOnServer.js as above, an alert will be shown when we load the page from browser. This will potentially enable attacker to execute arbitary code. To fix this vulnerability, we can make use of `serialize-javascript` package from Yahoo engineers and cleanse all initial state assignment from user input:
xss: serialize("</script><script>alert('Possible XSS vulnerability from user input!')</script>")
168
+
}
169
+
resolve({
170
+
globals: {
171
+
__INITIAL_STATE__: context
172
+
}
173
+
})
174
+
})
175
+
});
176
+
177
+
and when you inspect the HTML from browser you will see the tags are escaped:
178
+
179
+
window.__INITIAL_STATE__ = {"url":"/","xss":"\"\\u003C\\u002Fscript\\u003E\\u003Cscript\\u003Ealert('Possible XSS vulnerability from user input!')\\u003C\\u002Fscript\\u003E\""};
0 commit comments