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

Adding no-ancestor http header to apps (so they're guaranteed to be at _top) #591

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions libraries/psibase/common/include/psibase/Rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ namespace psibase
{
std::string name;
std::string value;

friend bool operator==(const HttpHeader& lhs, const HttpHeader& rhs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use = default

{
return lhs.name == rhs.name && lhs.value == rhs.value;
}
};

PSIO_REFLECT(HttpHeader, definitionWillNotChange(), name, value)

// TODO: consider adding headers to this
Expand Down
13 changes: 13 additions & 0 deletions services/system/ProxySys/src/ProxySys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,23 @@ namespace SystemService
// TODO: avoid repacking (both directions)
psibase::Actor<ServerInterface> iface(act.service, service);

auto reqTarget = req.target;

auto result = iface.serveSys(std::move(req));
if (result && !result->headers.empty() && serviceName != "common-sys")
abortMessage("service " + service.str() + " attempted to set an http header");

if (reqTarget.size() == 0 || reqTarget.starts_with("/index.html"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you really mean starts_with? ends_with or == would make more sense to me.

{
// Check if the target header is already in the vector; if the header was not found, add it
HttpHeader frameAncestorHeader = {"Content-Security-Policy", "frame-ancestors 'none';"};
auto pos = std::find(result->headers.begin(), result->headers.end(), frameAncestorHeader);
Comment on lines +91 to +92
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will miss many valid ways to spell the header.
Also, if the service has already provided a different value of frame-ancestors, do we still want to add frame-ancestors 'none'?

if (pos == result->headers.end())
{
result->headers.push_back(frameAncestorHeader);
}
}

setRetval(result);
} // serve()

Expand Down
Loading