mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-18 21:45:12 +00:00
prevent unsafe replacements of preloaded data etc
This commit is contained in:
@@ -360,11 +360,11 @@ function get_page_handler(App: Component, routes: RouteObject[], store_getter: (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const page = template()
|
const page = template()
|
||||||
.replace('%sapper.base%', `<base href="${req.baseUrl}/">`)
|
.replace('%sapper.base%', () => `<base href="${req.baseUrl}/">`)
|
||||||
.replace('%sapper.scripts%', `<script>${inline_script}</script>${scripts}`)
|
.replace('%sapper.scripts%', () => `<script>${inline_script}</script>${scripts}`)
|
||||||
.replace('%sapper.html%', html)
|
.replace('%sapper.html%', () => html)
|
||||||
.replace('%sapper.head%', `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`)
|
.replace('%sapper.head%', () => `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`)
|
||||||
.replace('%sapper.styles%', (css && css.code ? `<style>${css.code}</style>` : ''));
|
.replace('%sapper.styles%', () => (css && css.code ? `<style>${css.code}</style>` : ''));
|
||||||
|
|
||||||
res.statusCode = status;
|
res.statusCode = status;
|
||||||
res.end(page);
|
res.end(page);
|
||||||
|
|||||||
9
test/app/routes/unsafe-replacement.html
Normal file
9
test/app/routes/unsafe-replacement.html
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
$&
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
preload() {
|
||||||
|
return '$&';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -619,6 +619,16 @@ function run({ mode, basepath = '' }) {
|
|||||||
assert.equal(name, 'BODY');
|
assert.equal(name, 'BODY');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('replaces %sapper.xxx% tags safely', () => {
|
||||||
|
return nightmare
|
||||||
|
.goto(`${base}/unsafe-replacement`)
|
||||||
|
.init()
|
||||||
|
.page.html()
|
||||||
|
.then(html => {
|
||||||
|
assert.equal(html.indexOf('%sapper'), -1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user