Skip to content

Authenticate requests between components#486

Draft
execjosh wants to merge 1 commit into
felixhageloh:masterfrom
execjosh:authenticate-component-requests
Draft

Authenticate requests between components#486
execjosh wants to merge 1 commit into
felixhageloh:masterfrom
execjosh:authenticate-component-requests

Conversation

@execjosh
Copy link
Copy Markdown
Contributor

@execjosh execjosh commented Aug 5, 2022

Use a randomly generated token to authenticate requests to the server for all endpoints, including WebSockets, which will help prevent naïve exploitation of the privilege escalation threat of the /run/ endpoint. The token is passed to the node server via STDIN, which should sufficiently prevent eavesdropping.

There is a new setting that toggles this functionality and is enabled by default.

image

Implementation details

This is implemented using httpCookieStore, which is only available on macOS 10.13+. However this project targets 10.11.

The WKWebView injects the token as a cookie for requests from the foreground and background; so, this change should be transparent to all widgets. Additionally, the HttpOnly flag is set on the cookie, which prevents it from being accessed from JavaScript.

@execjosh execjosh force-pushed the authenticate-component-requests branch from d7f8aea to 4ae4169 Compare August 5, 2022 04:45
Comment thread server/src/ensureToken.js Outdated
@execjosh execjosh force-pushed the authenticate-component-requests branch from 4ae4169 to 31d9be9 Compare August 5, 2022 11:53
@execjosh execjosh force-pushed the authenticate-component-requests branch from 31d9be9 to 5a43805 Compare August 17, 2022 17:42

- (void)shutdown:(Boolean)keepAlive
{
if (shuttingDown) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this one is merged as a separate PR already :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebased 😄

Comment thread Uebersicht/UBAppDelegate.m Outdated
return dataDictionary;
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlPath];
[request setValue:@"Übersicht" forHTTPHeaderField:@"Origin"];
if (preferences.enableSecurity) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

might seem like a small thing, but what do you think about having this setting only control whether the server checks the token. It can be sent in all other places regardless.
This way the 'code surface' this setting impacts is reduced

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good point! I'll change the code to do that :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated.

// this will trigger a render
[self->screensController syncScreens:self];

[self fetchState:^(NSDictionary* state) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

is this one related to this change?

Copy link
Copy Markdown
Contributor Author

@execjosh execjosh Aug 20, 2022

Choose a reason for hiding this comment

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

Yes. From what I can tell, there is no way to send custom headers with HTTP requests through NSData. The results from NSURLSessionDataTask come asynchronously. So, we need to pass a callback.

Perhaps there is a synchronous way to make an HTTP request with custom headers?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

oh I see, I get the change now (misread at first)!

Use a randomly generated token to authenticate requests to the server for all
endpoints, including WebSockets.  The token is passed to the node server via
STDIN, which should sufficiently prevent eavesdropping.
@execjosh execjosh force-pushed the authenticate-component-requests branch from 5a43805 to 9c7cf76 Compare August 21, 2022 06:56
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Cm-6a-MW9">
<rect key="frame" x="220" y="265" width="182" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Enable security measures" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="6iu-kH-BSa">
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer to have one setting for each security measure?

Also, if it's fine to have one checkbox, is there a better wording?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I need to think about it a bit as well. Worst case I can play with it before releasing, so let's just leave as is for now.

@felixhageloh
Copy link
Copy Markdown
Owner

felixhageloh commented Aug 21, 2022

One thing I just came across is NSHTTPCookieStorage. I also vaguely remember looking at it (and maybe using it) when I first implemented this.
If I understand correctly, adding a cookie to the sharedHTTPCookieStorage will add the cookie to all requests sent by the app - not sure about web sockets, tho. If that's correct it would make the code a bit simpler

@felixhageloh
Copy link
Copy Markdown
Owner

@execjosh did you see my last comment here by any chance?

@execjosh
Copy link
Copy Markdown
Contributor Author

Oops, I must have missed it. I will try to have a look at NSHTTPCookieStorage when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants