Skip to content

Commit ba21dc3

Browse files
committed
javascript: fix "form.submit is not a function" errors
use HTMLFormElement.prototype.submit.call(document.forms[0]) on all Javascript auto-submit POST forms; affects: - OpenID Connect Implicit response type (OIDCResponseType id_token *) - Form Post response type (OIDCResponseMode form_post) - send authentication request via POST binding (OIDCProviderAuthRequestMethod POST) - preserving POST data (OIDCPreservePost On) Signed-off-by: Hans Zandbelt <[email protected]>
1 parent d883c95 commit ba21dc3

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
05/27/2025
22
- fix usage of OIDCPreservePostTemplates, regression in 2.4.17; see #1325; thanks @perry19987
3+
- javascript: use HTMLFormElement.prototype.submit.call(document.forms[0]) on all Javascript
4+
auto-submit POST forms to prevent browser Javascript error: "form.submit is not a function"
5+
affects:
6+
- OpenID Connect Implicit response type (OIDCResponseType id_token *)
7+
- Form Post response type (OIDCResponseMode form_post)
8+
- send authentication request via POST binding (OIDCProviderAuthRequestMethod POST)
9+
- preserving POST data (OIDCPreservePost On)
10+
see:
11+
https://trackjs.com/blog/when-form-submit-is-not-a-function/
12+
https://stackoverflow.com/questions/833032/submit-is-not-a-function-error-in-javascript
13+
https://www.geeksforgeeks.org/how-to-solve-submit-is-not-a-function-error-in-javascript/
314

415
05/22/2025
516
- metrics: avoid possible segfault after restart twice; thanks @atzm

src/handle/response.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ apr_byte_t oidc_response_post_preserve_javascript(request_rec *r, const char *lo
150150
return TRUE;
151151
}
152152

153-
const char *jmethod = "preserveOnLoad";
153+
const char *jmethod = "preserveOnLoad()";
154154
const char *jscript = apr_psprintf(
155155
r->pool,
156156
" <script type=\"text/javascript\">\n"
157-
" function %s() {\n"
157+
" function %s {\n"
158158
" sessionStorage.setItem('mod_auth_openidc_preserve_post_params', JSON.stringify(%s));\n"
159159
" %s"
160160
" }\n"
@@ -179,7 +179,7 @@ static int oidc_response_post_preserved_restore(request_rec *r, const char *orig
179179

180180
oidc_debug(r, "enter: original_url=%s", original_url);
181181

182-
const char *method = "postOnLoad";
182+
const char *method = "postOnLoad()";
183183
const char *script =
184184
apr_psprintf(r->pool,
185185
" <script type=\"text/javascript\">\n"
@@ -191,7 +191,7 @@ static int oidc_response_post_preserved_restore(request_rec *r, const char *orig
191191
" }\n"
192192
" return result;\n"
193193
" }\n"
194-
" function %s() {\n"
194+
" function %s {\n"
195195
" var mod_auth_openidc_preserve_post_params = "
196196
"JSON.parse(sessionStorage.getItem('mod_auth_openidc_preserve_post_params'));\n"
197197
" sessionStorage.removeItem('mod_auth_openidc_preserve_post_params');\n"
@@ -203,7 +203,7 @@ static int oidc_response_post_preserved_restore(request_rec *r, const char *orig
203203
" document.forms[0].appendChild(input);\n"
204204
" }\n"
205205
" document.forms[0].action = \"%s\";\n"
206-
" document.forms[0].submit();\n"
206+
" HTMLFormElement.prototype.submit.call(document.forms[0]);\n"
207207
" }\n"
208208
" </script>\n",
209209
method, oidc_util_html_javascript_escape(r->pool, original_url));

src/handle/session_management.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int oidc_session_management_iframe_rp(request_rec *r, oidc_cfg_t *c, oidc
138138
java_script = apr_psprintf(r->pool, java_script, origin, client_id, session_state ? session_state : "",
139139
login_uri ? login_uri : "", op_iframe_id, poll_interval, redirect_uri, redirect_uri);
140140

141-
return oidc_util_html_content_prep(r, OIDC_REQUEST_STATE_KEY_HTML, NULL, java_script, "setTimer", NULL);
141+
return oidc_util_html_content_prep(r, OIDC_REQUEST_STATE_KEY_HTML, NULL, java_script, "setTimer()", NULL);
142142
}
143143

144144
/*

src/mod_auth_openidc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ static int oidc_javascript_implicit(request_rec *r, oidc_cfg_t *c) {
977977
" document.forms[0].appendChild(input);\n"
978978
" }\n"
979979
" document.forms[0].action = window.location.href.substr(0, window.location.href.indexOf('#'));\n"
980-
" document.forms[0].submit();\n"
980+
" HTMLFormElement.prototype.submit.call(document.forms[0]);\n"
981981
" }\n"
982982
" </script>\n";
983983

@@ -990,7 +990,7 @@ static int oidc_javascript_implicit(request_rec *r, oidc_cfg_t *c) {
990990
" </form>\n";
991991

992992
/* prepare HTML/Javascript page to be sent in the content handler */
993-
return oidc_util_html_content_prep(r, OIDC_REQUEST_STATE_KEY_HTML, "Submitting...", java_script, "postOnLoad",
993+
return oidc_util_html_content_prep(r, OIDC_REQUEST_STATE_KEY_HTML, "Submitting...", java_script, "postOnLoad()",
994994
html_body);
995995
}
996996

src/proto/request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ int oidc_proto_request_auth(request_rec *r, struct oidc_provider_t *provider, co
693693

694694
/* signal this to the content handler */
695695
rv = oidc_util_html_content_prep(r, OIDC_REQUEST_STATE_KEY_AUTHN_POST, "Submitting...", NULL,
696-
"document.forms[0].submit", html_body);
696+
"HTMLFormElement.prototype.submit.call(document.forms[0])", html_body);
697697

698698
} else if (oidc_proto_profile_auth_request_method_get(provider) == OIDC_AUTH_REQUEST_METHOD_PAR) {
699699

@@ -722,7 +722,7 @@ int oidc_proto_request_auth(request_rec *r, struct oidc_provider_t *provider, co
722722
if (oidc_request_state_get(r, OIDC_REQUEST_STATE_KEY_HTTP) == NULL) {
723723
/* signal this to the content handler */
724724
rv = oidc_util_html_content_prep(r, OIDC_REQUEST_STATE_KEY_AUTHN_PRESERVE,
725-
"Preserving...", javascript, "preserveOnLoad",
725+
"Preserving...", javascript, "preserveOnLoad()",
726726
"<p>Preserving...</p>");
727727
}
728728
}

src/util/html.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ int oidc_util_html_send(request_rec *r, const char *title, const char *html_head
188188
" </body>\n"
189189
"</html>\n";
190190

191-
html = apr_psprintf(
192-
r->pool, html, title ? oidc_util_html_escape(r->pool, title) : "", html_head ? html_head : "",
193-
on_load ? apr_psprintf(r->pool, " onload=\"%s()\"", on_load) : "", html_body ? html_body : "<p></p>");
191+
html = apr_psprintf(r->pool, html, title ? oidc_util_html_escape(r->pool, title) : "",
192+
html_head ? html_head : "", on_load ? apr_psprintf(r->pool, " onload=\"%s\"", on_load) : "",
193+
html_body ? html_body : "<p></p>");
194194

195195
return oidc_util_http_send(r, html, _oidc_strlen(html), OIDC_HTTP_CONTENT_TYPE_TEXT_HTML, status_code);
196196
}

test/post_restore.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
document.forms[0].appendChild(input);
2424
}
2525
document.forms[0].action = "%s";
26-
document.forms[0].submit();
26+
HTMLFormElement.prototype.submit.call(document.forms[0]);
2727
}
2828
</script>
2929
</head>

0 commit comments

Comments
 (0)