Skip to content
Open
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: 7 additions & 1 deletion crates/server/src/console/pages/role_pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ pub async fn new_role_form(
(&account_id, Some(&format!("/console/accounts/{eid}"))),
("New Role", None),
]);
// The default principal is the account's root, which every principal of
// the account matches. `create_role` refuses a principal ARN that holds a
// wildcard, so the default must not carry one.
let root_principal = html::escape(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test holds this escape: with html::escape removed the new test still passes, and an admin who opens /console/accounts/x"</textarea><script>alert(1)</script>/roles/new then gets a raw <script> element in the page; at this head the same request stays inside the box and decodes to valid JSON. A test that requests a path with markup and checks the box would hold it. Separately, the body says the test with the old default "fails with the wildcard error"; it fails earlier, at the principal check at test_console_integration.py:430, and never submits the form.

&serde_json::Value::String(format!("arn:aws:iam::{account_id}:root")).to_string(),
);

let content = format!(
r#"{crumbs}<h1>Create Role</h1>
Expand All @@ -51,7 +57,7 @@ pub async fn new_role_form(
"Version": "2012-10-17",
"Statement": [{{
"Effect": "Allow",
"Principal": {{"AWS": "arn:aws:iam::*:user/*"}},
"Principal": {{"AWS": {root_principal}}},
"Action": "sts:AssumeRole"
}}]
}}</textarea>
Expand Down
26 changes: 26 additions & 0 deletions tests/test_console_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from __future__ import annotations

import html
import json
import os
import re
Expand Down Expand Up @@ -418,6 +419,31 @@ def test_create_and_view_role(self):

self.console.post(f"/accounts/{self.account_id}/roles/{role}/delete")

def test_create_role_with_the_form_default_trust_policy(self):
resp = self.console.get(f"/accounts/{self.account_id}/roles/new")
assert resp.status_code == 200
m = re.search(
r'<textarea id="trust_policy"[^>]*>(.*?)</textarea>', resp.text, re.S
)
assert m, "the New Role form has a trust policy box"
default_policy = html.unescape(m.group(1))
assert json.loads(default_policy)["Statement"][0]["Principal"] == {
"AWS": f"arn:aws:iam::{self.account_id}:root"
}

role = f"df-{uuid.uuid4().hex[:8]}"
resp = self.console.post(f"/accounts/{self.account_id}/roles/new", {
"role_name": role,
"trust_policy": default_policy,
})
assert resp.status_code == 303, resp.text

resp = self.console.get(f"/accounts/{self.account_id}/roles/{role}")
assert resp.status_code == 200
assert role in resp.text

self.console.post(f"/accounts/{self.account_id}/roles/{role}/delete")

def test_delete_role(self):
role = f"dr-{uuid.uuid4().hex[:8]}"
self.console.post(f"/accounts/{self.account_id}/roles/new", {
Expand Down
Loading