Skip to content

Commit

Permalink
Merge pull request #141 from sebadob/139-error-page-fix
Browse files Browse the repository at this point in the history
HTML error template path fixes
  • Loading branch information
sebadob authored Nov 3, 2023
2 parents a24a257 + 3c22ca4 commit 5965d9a
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docs/config/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ <h1 id="reference-config"><a class="header" href="#reference-config">Reference C
EVENT_LEVEL_IP_BLACKLISTED=warning
# The level for the generated Event after certain amounts of false
# logins from an IP
# default: criticao
# default: critical
EVENT_LEVEL_FAILED_LOGINS_25=critical
# default: criticao
# default: critical
EVENT_LEVEL_FAILED_LOGINS_20=critical
# default: warning
EVENT_LEVEL_FAILED_LOGINS_15=warning
Expand Down
4 changes: 2 additions & 2 deletions docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,9 @@ <h4 id="config-adjustements---rest-api"><a class="header" href="#config-adjustem
EVENT_LEVEL_IP_BLACKLISTED=warning
# The level for the generated Event after certain amounts of false
# logins from an IP
# default: criticao
# default: critical
EVENT_LEVEL_FAILED_LOGINS_25=critical
# default: criticao
# default: critical
EVENT_LEVEL_FAILED_LOGINS_20=critical
# default: warning
EVENT_LEVEL_FAILED_LOGINS_15=warning
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions frontend/src/components/Error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script>
import { slide } from 'svelte/transition';
import IconChevronRight from "$lib/icons/IconChevronRight.svelte";
import WithI18n from "$lib/WithI18n.svelte";
import BrowserCheck from "./BrowserCheck.svelte";
import LangSelector from "$lib/LangSelector.svelte";
let t;
let showDetails = false;
</script>

<BrowserCheck>
<WithI18n bind:t content="error">
<h1>{t.error}</h1>
<p>{t.errorText}</p>

{#if t.detailsText}
<div
role="button"
tabindex="0"
class="showDetails"
on:click={() => showDetails = !showDetails}
on:keypress={() => showDetails = !showDetails}
>
{t.details}
<div
class="chevron"
style:margin-top={showDetails ? '' : '-5px'}
style:transform={showDetails ? 'rotate(90deg)' : 'rotate(180deg)'}
>
<IconChevronRight
color="var(--col-act2)"
width=16
/>
</div>
</div>

{#if showDetails}
<div transition:slide class="details">
{t.detailsText}
</div>
{/if}
{/if}

<LangSelector absolute />
</WithI18n>
</BrowserCheck>

<style>
.chevron {
transition: all 250ms;
}
.showDetails {
display: inline-flex;
align-items: center;
gap: .1rem;
cursor: pointer;
color: var(--col-act2);
}
.showDetails:hover {
color: var(--col-act2a);
}
</style>
65 changes: 2 additions & 63 deletions frontend/src/routes/error/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,66 +1,5 @@
<script>
import { slide } from 'svelte/transition';
import IconChevronRight from "$lib/icons/IconChevronRight.svelte";
import WithI18n from "$lib/WithI18n.svelte";
import BrowserCheck from "../../components/BrowserCheck.svelte";
import LangSelector from "$lib/LangSelector.svelte";
let t;
let showDetails = false;
import Error from "../../components/Error.svelte";
</script>

<BrowserCheck>
<WithI18n bind:t content="error">
<h1>{t.error}</h1>
<p>{t.errorText}</p>

{#if t.detailsText}
<div
role="button"
tabindex="0"
class="showDetails"
on:click={() => showDetails = !showDetails}
on:keypress={() => showDetails = !showDetails}
>
{t.details}
<div
class="chevron"
style:margin-top={showDetails ? '' : '-5px'}
style:transform={showDetails ? 'rotate(90deg)' : 'rotate(180deg)'}
>
<IconChevronRight
color="var(--col-act2)"
width=16
/>
</div>
</div>

{#if showDetails}
<div transition:slide class="details">
{t.detailsText}
</div>
{/if}
{/if}

<LangSelector absolute />
</WithI18n>
</BrowserCheck>

<style>
.chevron {
transition: all 250ms;
}
.showDetails {
display: inline-flex;
align-items: center;
gap: .1rem;
cursor: pointer;
color: var(--col-act2);
}
.showDetails:hover {
color: var(--col-act2a);
}
</style>
<Error/>
5 changes: 5 additions & 0 deletions frontend/src/routes/error/error/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import Error from "../../../components/Error.svelte";
</script>

<Error/>
5 changes: 5 additions & 0 deletions frontend/src/routes/error/error/error/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import Error from "../../../../components/Error.svelte";
</script>

<Error/>
5 changes: 5 additions & 0 deletions frontend/src/routes/error/error/error/error/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import Error from "../../../../../components/Error.svelte";
</script>

<Error/>
25 changes: 3 additions & 22 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ build-ui:
PAGES=(
"templates/html/*.html"
"templates/html/admin/*.html"
"templates/html/error/*.html"
"templates/html/error/error/*.html"
"templates/html/error/error/error/*.html"
"templates/html/oidc/*.html"
"templates/html/users/*.html"
"templates/html/users/{id}/reset/*.html"
Expand Down Expand Up @@ -244,28 +247,6 @@ publish-nightly: build-sqlite build-postgres
docker push ghcr.io/sebadob/rauthy:nightly-lite


multi-platform-test:
#!/usr/bin/env bash
# build and push sqlite version
docker buildx build \
-t ghcr.io/sebadob/rauthy:multi-arch-test \
--platform linux/amd64,linux/arm64 \
--build-arg="DB=sqlite" \
--no-cache \
--push \
.

# build and push postgres version
docker buildx build \
-t ghcr.io/sebadob/rauthy:multi-arch-test \
--platform linux/amd64,linux/arm64 \
--build-arg="DB=postgres" \
--no-cache \
--push \
.


# publishes the application images - full pipeline incl clippy and testing
publish-versions: pull-latest-cross build-docs build-ui build-sqlite build-postgres
#!/usr/bin/env bash
Expand Down
10 changes: 4 additions & 6 deletions rauthy-handlers/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rauthy_models::response::{
use rauthy_models::templates::{
AccountHtml, AdminApiKeysHtml, AdminAttributesHtml, AdminBlacklistHtml, AdminClientsHtml,
AdminConfigHtml, AdminDocsHtml, AdminGroupsHtml, AdminHtml, AdminRolesHtml, AdminScopesHtml,
AdminSessionsHtml, AdminUsersHtml, ErrorHtml, IndexHtml,
AdminSessionsHtml, AdminUsersHtml, IndexHtml,
};
use rauthy_service::encryption;
use redhac::{cache_get, cache_get_from, cache_get_value, QuorumHealth, QuorumState};
Expand All @@ -64,10 +64,8 @@ pub async fn get_index(

#[get("/{_:.*}")]
pub async fn get_static_assets(
data: web::Data<AppState>,
path: web::Path<String>,
accept_encoding: web::Header<header::AcceptEncoding>,
req: HttpRequest,
) -> HttpResponse {
let path = path.into_inner();
let accept_encoding = accept_encoding.into_inner();
Expand All @@ -88,9 +86,9 @@ pub async fn get_static_assets(
.content_type(mime.first_or_octet_stream().as_ref())
.body(content.data.into_owned()),
None => {
let colors = ColorEntity::find_rauthy(&data).await.unwrap_or_default();
let lang = Language::try_from(&req).unwrap_or_default();
ErrorHtml::response(&colors, &lang, StatusCode::NOT_FOUND, None)
// Since this may resolve to a sub url path of any length, we cannot now, which
// error template we need to serve -> just return not found
HttpResponse::NotFound().finish()
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions rauthy-handlers/src/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use actix_web::cookie::time::OffsetDateTime;
use actix_web::http::header::HeaderValue;
use actix_web::http::{header, StatusCode};
use actix_web::{get, post, web, HttpRequest, HttpResponse};
use actix_web::{get, post, web, HttpRequest, HttpResponse, ResponseError};
use tracing::debug;

use rauthy_common::constants::{COOKIE_MFA, HEADER_HTML, SESSION_LIFETIME};
Expand All @@ -19,11 +19,13 @@ use rauthy_models::entity::users::User;
use rauthy_models::entity::webauthn::WebauthnCookie;
use rauthy_models::language::Language;
use rauthy_models::request::{
AuthRequest, LoginRefreshRequest, LoginRequest, LogoutRequest,
TokenRequest, TokenValidationRequest,
AuthRequest, LoginRefreshRequest, LoginRequest, LogoutRequest, TokenRequest,
TokenValidationRequest,
};
use rauthy_models::response::{JWKSCerts, JWKSPublicKeyCerts, SessionInfoResponse};
use rauthy_models::templates::{AuthorizeHtml, CallbackHtml, ErrorHtml, FrontendAction};
use rauthy_models::templates::{
AuthorizeHtml, CallbackHtml, Error1Html, ErrorHtml, FrontendAction,
};
use rauthy_models::JwtCommonClaims;
use rauthy_service::auth;

Expand Down Expand Up @@ -67,7 +69,9 @@ pub async fn get_authorize(
{
Ok(res) => res,
Err(err) => {
return Ok(ErrorHtml::response_from_err(&colors, &lang, err));
let status = err.status_code();
let (body, nonce) = Error1Html::build(&colors, &lang, status, Some(err.message));
return Ok(ErrorHtml::response(body, nonce, status));
}
};

Expand All @@ -92,7 +96,9 @@ pub async fn get_authorize(

let session = Session::new(*SESSION_LIFETIME, real_ip_from_req(&req));
if let Err(err) = session.save(&data).await {
return Ok(ErrorHtml::response_from_err(&colors, &lang, err));
let status = err.status_code();
let (body, nonce) = Error1Html::build(&colors, &lang, status, Some(err.message));
return Ok(ErrorHtml::response(body, nonce, status));
}

let mut action = FrontendAction::None;
Expand Down
20 changes: 13 additions & 7 deletions rauthy-handlers/src/users.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{real_ip_from_req, ReqPrincipal};
use actix_web::http::StatusCode;
use actix_web::{cookie, delete, get, post, put, web, HttpRequest, HttpResponse};
use actix_web::{cookie, delete, get, post, put, web, HttpRequest, HttpResponse, ResponseError};
use rauthy_common::constants::{
COOKIE_MFA, HEADER_HTML, OPEN_USER_REG, PWD_RESET_COOKIE, USER_REG_DOMAIN_RESTRICTION,
};
Expand All @@ -26,7 +26,7 @@ use rauthy_models::response::{
PasskeyResponse, UserAttrConfigResponse, UserAttrValueResponse, UserAttrValuesResponse,
UserResponse,
};
use rauthy_models::templates::{ErrorHtml, UserRegisterHtml};
use rauthy_models::templates::{Error1Html, Error3Html, ErrorHtml, UserRegisterHtml};
use rauthy_service::password_reset;
use std::ops::Add;
use time::OffsetDateTime;
Expand Down Expand Up @@ -224,12 +224,14 @@ pub async fn get_users_register(
let lang = Language::try_from(&req).unwrap_or_default();

if !*OPEN_USER_REG {
return Ok(ErrorHtml::response(
let status = StatusCode::NOT_FOUND;
let (body, nonce) = Error1Html::build(
&colors,
&lang,
StatusCode::NOT_FOUND,
status,
Some("Open User Registration is disabled".to_string()),
));
);
return Ok(ErrorHtml::response(body, nonce, status));
}

let (body, nonce) = UserRegisterHtml::build(&colors, &lang);
Expand Down Expand Up @@ -406,7 +408,9 @@ pub async fn get_user_email_confirm(
.body(html),
Err(err) => {
let colors = ColorEntity::find_rauthy(&data).await.unwrap_or_default();
ErrorHtml::response_from_err(&colors, &lang, err)
let status = err.status_code();
let (body, nonce) = Error3Html::build(&colors, &lang, status, Some(err.message));
ErrorHtml::response(body, nonce, status)
}
}
}
Expand Down Expand Up @@ -441,7 +445,9 @@ pub async fn get_user_password_reset(
.body(html),
Err(err) => {
let colors = ColorEntity::find_rauthy(&data).await.unwrap_or_default();
ErrorHtml::response_from_err(&colors, &lang, err)
let status = err.status_code();
let (body, nonce) = Error3Html::build(&colors, &lang, status, Some(err.message));
ErrorHtml::response(body, nonce, status)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion rauthy-main/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ async fn actix_main(app_state: web::Data<AppState>) -> std::io::Result<()> {
.service(generic::get_password_policy)
.service(generic::put_password_policy)
.service(generic::get_pow)
// .service(oidc::post_refresh_token)
.service(groups::get_groups)
.service(groups::post_group)
.service(groups::put_group)
Expand Down
Loading

0 comments on commit 5965d9a

Please sign in to comment.