Skip to content

Commit 9270b61

Browse files
refactor: removed inline script from form post html
This accommodates the ability to whitelist form post in a CSP policy. See #716
1 parent 7ee699f commit 9270b61

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

lib/response_modes/form_post.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ module.exports = function formPost(ctx, action, inputs) {
1616
ctx.body = `<!DOCTYPE html>
1717
<head>
1818
<title>Submitting Callback</title>
19+
<script>
20+
document.addEventListener('DOMContentLoaded', function () { document.forms[0].submit() });
21+
</script>
1922
</head>
20-
<body onload="javascript:document.forms[0].submit()">
23+
<body>
2124
<form method="post" action="${action}">
2225
${formInputs}
2326
<noscript>

test/device_code/code_verification_endpoint.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('GET code_verification endpoint', () => {
3131
.query({ user_code: '123-456-789' })
3232
.expect(200)
3333
.expect('content-type', 'text/html; charset=utf-8')
34-
.expect(/<body onload="javascript:document\.forms\[0]\.submit\(\)"/)
34+
.expect(/document.addEventListener\('DOMContentLoaded', function \(\) { document.forms\[0\].submit\(\) }\);/)
3535
.expect(({ text }) => {
3636
({ state: { secret } } = this.getSession());
3737
expect(text).to.match(new RegExp(`input type="hidden" name="xsrf" value="${secret}"`));

test/device_code/device_resume.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ describe('device interaction resume /device/:user_code/:uid/', () => {
375375
await this.agent.get(path)
376376
.expect(200)
377377
.expect('content-type', 'text/html; charset=utf-8')
378-
.expect(/<body onload="javascript:document\.forms\[0]\.submit\(\)"/)
378+
.expect(/document.addEventListener\('DOMContentLoaded', function \(\) { document.forms\[0\].submit\(\) }\);/)
379379
.expect(/<input type="hidden" name="logout" value="yes"\/>/)
380380
.expect(({ text }) => {
381381
({ state } = this.getSession());

test/interaction/interaction.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ describe('resume after consent', () => {
512512
await this.agent.get('/auth/resume')
513513
.expect(200)
514514
.expect('content-type', 'text/html; charset=utf-8')
515-
.expect(/<body onload="javascript:document\.forms\[0]\.submit\(\)"/)
515+
.expect(/document.addEventListener\('DOMContentLoaded', function \(\) { document.forms\[0\].submit\(\) }\);/)
516516
.expect(/<input type="hidden" name="logout" value="yes"\/>/)
517517
.expect(({ text }) => {
518518
({ state } = this.getSession());

0 commit comments

Comments
 (0)