Skip to content

Commit

Permalink
Add public/400.html file rendered on bad request
Browse files Browse the repository at this point in the history
  • Loading branch information
dari-us authored and martinemde committed Aug 31, 2024
1 parent c17aad8 commit 96de9e3
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 1 deletion.
67 changes: 67 additions & 0 deletions actionmailbox/test/dummy/public/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The server cannot process the request due to a client error (400)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}

.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body class="rails-default-error-page">
<!-- This file lives in public/400.html -->
<div class="dialog">
<div>
<h1>The server cannot process the request due to a client error.</h1>
<p>Please check the request and try again.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
We suggest replacing `params.require(:person).permit(:name, :age)`
with the direct replacement `params.expect(person: [:name, :age])`
to prevent external users from manipulating params to trigger 500
errors. A propery 400 error will be returned instead.
errors. A 400 error will be returned instead, using public/400.html

Usage of `params.require(:id)` should likewise be replaced with
`params.expect(:id)` which is designed to ensure that `params[:id]`
Expand Down
67 changes: 67 additions & 0 deletions actiontext/test/dummy/public/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The server cannot process the request due to a client error (400)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}

.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body class="rails-default-error-page">
<!-- This file lives in public/400.html -->
<div class="dialog">
<div>
<h1>The server cannot process the request due to a client error.</h1>
<p>Please check the request and try again.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
67 changes: 67 additions & 0 deletions activestorage/test/dummy/public/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The server cannot process the request due to a client error (400)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}

.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body class="rails-default-error-page">
<!-- This file lives in public/400.html -->
<div class="dialog">
<div>
<h1>The server cannot process the request due to a client error.</h1>
<p>Please check the request and try again.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def delete_app_views_if_api_option

def delete_public_files_if_api_option
if options[:api]
remove_file "public/400.html"
remove_file "public/404.html"
remove_file "public/406-unsupported-browser.html"
remove_file "public/422.html"
Expand Down
67 changes: 67 additions & 0 deletions railties/lib/rails/generators/rails/app/templates/public/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>The server cannot process the request due to a client error (400)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}

.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top-color: #DADADA;
color: #666;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body class="rails-default-error-page">
<!-- This file lives in public/400.html -->
<div class="dialog">
<div>
<h1>The server cannot process the request due to a client error.</h1>
<p>Please check the request and try again.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions railties/test/generators/api_app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def skipped_files
config/initializers/assets.rb
config/initializers/content_security_policy.rb
test/helpers
public/400.html
public/404.html
public/422.html
public/406-unsupported-browser.html
Expand Down
1 change: 1 addition & 0 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
db/seeds.rb
lib/tasks/.keep
log/.keep
public/400.html
public/404.html
public/406-unsupported-browser.html
public/422.html
Expand Down
1 change: 1 addition & 0 deletions railties/test/generators/plugin_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
test/dummy/config/routes.rb
test/dummy/config/storage.yml
test/dummy/log/.keep
test/dummy/public/400.html
test/dummy/public/404.html
test/dummy/public/406-unsupported-browser.html
test/dummy/public/422.html
Expand Down

0 comments on commit 96de9e3

Please sign in to comment.