Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: combine requests #73

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/http_server/index_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use {
serde::Deserialize,
};

const TEMPLATE: &str = r#"
const csrfToken = '{token}';
pub const SCRIPT: &str = r#"
// event subscribed by Verify Enclave
window.addEventListener("message", (event) => {
const attestationId = event.data
Expand Down Expand Up @@ -42,9 +41,10 @@ pub(super) struct Params {
}

pub(super) async fn get(query: Query<Params>) -> Result<impl IntoResponse, StatusCode> {
if !CsrfToken::validate_format(&query.token) {
let token = &query.token;
if !CsrfToken::validate_format(token) {
return Err(StatusCode::BAD_REQUEST);
}

Ok(Html(TEMPLATE.replacen("{token}", &query.token, 1)))
Ok(Html(format!("const csrfToken = '{token}';{SCRIPT}")))
}
14 changes: 6 additions & 8 deletions src/http_server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {
self::index_js::SCRIPT,
crate::{
ContextualCommand,
Domain,
Expand Down Expand Up @@ -38,9 +39,9 @@ use {
tap::{Pipe, Tap},
tower_http::cors::{self, CorsLayer},
tracing::{info, instrument},
wc::{
geoip,
geoip::block::{middleware::GeoBlockLayer, BlockingPolicy as GeoBlockingPolicy},
wc::geoip::{
self,
block::{middleware::GeoBlockLayer, BlockingPolicy as GeoBlockingPolicy},
},
};

Expand Down Expand Up @@ -132,7 +133,7 @@ pub async fn run<S, G>(
.layer(cors_layer)
.route("/health", get(health::get(health_provider)))
.route("/attestation", post(attestation::post))
.route("/index.js", get(index_js::get))
.route("/index.js", get(index_js::get)) // TODO remove in next deploy
.route("/:project_id", get(root))
.layer(metrics_layer)
.with_state(Arc::new(state));
Expand Down Expand Up @@ -168,10 +169,7 @@ pub async fn run<S, G>(
}

fn index_html(token: &str) -> String {
format!(
"<!-- index.html --><html><head><script \
src=\"/index.js?token={token}\"></script></head></html>"
)
format!("<script>const csrfToken = '{token}';{SCRIPT}</script>")
}

const UNKNOWN_PROJECT_MSG: &str = "Project with the provided ID doesn't exist. Please, ensure \
Expand Down