Skip to content

Making proper use of strictOrigins - #1118

Merged
kjetilk merged 16 commits into
release/v5.0.0from
fix/faulty-403
Mar 8, 2019
Merged

kjetilk merged 16 commits into
release/v5.0.0from
fix/faulty-403

Conversation

@megoth

@megoth megoth commented Feb 28, 2019

Copy link
Copy Markdown
Contributor

We had some faulty handling where we returned 403 even if the user wasn't authenticated. (This fixes #1117.)

Some notes

  1. Discovered some redundant tests in test/integration/authentication-oidc-test.js, and moved some tests into groups for better overview. This makes for a lot of changes, but I think it's worth it.
  2. Duplicated authentication-oidc-test into authentication-oidc-with-strict-origins-turned-off-test to make sure we handle those permutations correctly as well. This required a lot of setup, which are all of the new files in this commit.
  3. Tried to consolidate the use of getTrustedOrigins in create-app.js, which made a test obsolete

@megoth

megoth commented Feb 28, 2019

Copy link
Copy Markdown
Contributor Author

I realize the number of changes introduced in test/integration/authentication-oidc-test.js might be a bit too much...

@kjetilk @RubenVerborgh @dmitrizagidulin let me know if you want me to ungroup the tests in that file, it should reduce the number of changes a lot. But it also makes it harder to get an overview of the tests =/ (which had already created some redundant tests)

@megoth

megoth commented Feb 28, 2019

Copy link
Copy Markdown
Contributor Author

Could also move test/integration/authentication-oidc-with-strict-origins-turned-off-test.js into a separate commit, if wanted; that would also reduce the number of changes a lot.

Comment thread lib/acl-checker.js Outdated
const agentOrigin = this.agentOrigin ? rdf.sym(this.agentOrigin) : null
const trustedOrigins = this.trustedOrigins ? this.trustedOrigins.map(trustedOrigin => rdf.sym(trustedOrigin)) : null
const agentOrigin = this.strictOrigin && this.agentOrigin ? rdf.sym(this.agentOrigin) : null
const trustedOrigins = this.strictOrigin && this.trustedOrigins ? this.trustedOrigins.map(trustedOrigin => rdf.sym(trustedOrigin)) : null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We do this every time? That might get expensive.

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.

Are you thinking of the use of Array.prototype.map-method and/or the use of ternary operators?

Comment thread lib/create-app.js Outdated
// (https://github.com/solid/node-solid-server/pull/835#issuecomment-426429003)
if (!argv.host.allowsSessionFor(userId, origin, trustedOrigins) && !isLogoutRequest(req)) {
// We only want to do this check if strictOrigin is set to false, since we trust WebACL to handle origins otherwise
// If we don't allow authentication with cookies we can't handle ACLs properly wrt trusted origins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's not the right explanation. We can handle ACLs properly; with non-cookie auth mechanisms.

The full explanation is:

Authentication cookies are an optimization:
instead of going through the process of
fully validating authentication on every request,
we go through this process once,
and store its successful result in a cookie
that will be reused upon the next request.
However, that cookie can then be sent by any server,
even servers that have not gone through the proper authentication mechanism.
However, if trusted origins are enabled,
then any origin is allowed to take the shortcut route,
since malicious origins will be banned at the ACL checking phase.

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.

I'm having problem wrapping my head around the reasoning for this part of the code, so thank you for the explanation. I think it's a good explanation, so I added it to the PR, hope that's ok.

Comment thread lib/models/solid-host.js Outdated
if (originHost === userHost) return true
if (trustedOrigins.includes(origin)) return true
return false
return !!trustedOrigins.includes(origin)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

which by default included the user's own domain?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Apparently not, given the test: is this intended?

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.

I tried to reuse ldp.getTrustedOrigins, which includes the user's own domain if the server is a multiuser server.

I thought we could remove some redundant code, but maybe I should revert this change back, since others might not use ldp.getTrustedOrigins?

@megoth megoth mentioned this pull request Feb 28, 2019
RubenVerborgh and others added 5 commits March 2, 2019 21:51
We had some faulty handling where we returned 403 even if the user wasn't authenticated. (This fixes #1117.)

1. I discovered some redundant tests in test/integration/authentication-oidc-test.js, and moved some tests into groups for better overview. This makes for a lot of changes, but I think it's worth it.
2. I duplicated authentication-oidc-test into authentication-oidc-with-strict-origins-turned-off-test to make sure we handle those permutations correctly as well. This required a lot of setup, which are all of the new files in this commit.
3. I tried to consolidate the use of getTrustedOrigins in create-app.js, which made a test obsolete
My previous explanation was wrong
@megoth

megoth commented Mar 2, 2019

Copy link
Copy Markdown
Contributor Author

I just discovered that some tests will fail if run by themselves, but succeed if run as part of running all tests in that file...

An example of this is "ACL with WebID+OIDC over HTTP > Origin > user1 should be able to access test directory". This should actually fail, at least if I understand the logic correctly.

I will try to commit a fix for this soon.

@megoth megoth mentioned this pull request Mar 2, 2019
@megoth

megoth commented Mar 3, 2019

Copy link
Copy Markdown
Contributor Author

Added two more commits that removes the need of ordering in tests running in test/integration/acl-oidc-test.js and test/integration/acl-tls-test.js.

I think these commits could've been extracted into a separate PR for clarity. Let me know if this is desired.

megoth added a commit that referenced this pull request Mar 3, 2019
@megoth
megoth requested a review from RubenVerborgh March 6, 2019 12:11
@megoth

megoth commented Mar 6, 2019

Copy link
Copy Markdown
Contributor Author

@RubenVerborgh I moved some code into the constructor of the ACLChecker, tests verifies it works nicely ^_^

I've fell a bit out of loop on this PR, were there more feedback you had that I should fix?

@kjetilk kjetilk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, it looks good. What makes me uneasy is the very extensive changes to authentication-oidc-test.js, since a lot of lines have changed, it had very thorough review before this, so I was thinking that not much should change in there.

I suppose your tooling did many of those changes, @megoth , so perhaps it is just that, but it is hard for me to see what has actually changed there.

@kjetilk
kjetilk requested review from dmitrizagidulin and removed request for dmitrizagidulin March 7, 2019 11:01
@megoth

megoth commented Mar 7, 2019

Copy link
Copy Markdown
Contributor Author

OK, it looks good. What makes me uneasy is the very extensive changes to authentication-oidc-test.js, since a lot of lines have changed, it had very thorough review before this, so I was thinking that not much should change in there.

I suppose your tooling did many of those changes, @megoth , so perhaps it is just that, but it is hard for me to see what has actually changed there.

It was a deliberate choice, because the tests were badly grouped which made them very hard to read.

But I can revert those changes and we could live with it instead of having this many changes.

@kjetilk

kjetilk commented Mar 7, 2019

Copy link
Copy Markdown
Member

It was a deliberate choice, because the tests were badly grouped which made them very hard to read.

But I can revert those changes and we could live with it instead of having this many changes.

I'm all for cleaning up, but this ended up being a rather large change, and I find it hard to review. So, perhaps the grouping changes could be done in a separate PR? Would that be a lot of work at this point?

@megoth

megoth commented Mar 7, 2019

Copy link
Copy Markdown
Contributor Author

It was a deliberate choice, because the tests were badly grouped which made them very hard to read.
But I can revert those changes and we could live with it instead of having this many changes.

I'm all for cleaning up, but this ended up being a rather large change, and I find it hard to review. So, perhaps the grouping changes could be done in a separate PR? Would that be a lot of work at this point?

I'm going to try to revert the big changes to authentication-oidc-test.js, so that you only have to review my added tests ^_^

@megoth

megoth commented Mar 7, 2019

Copy link
Copy Markdown
Contributor Author

@kjetilk I've reverted a bunch of unnecessary changes, most of the changes are now simply new files. Let me know if you want me to do more 😸


it('should return a 403', () => {
expect(response).to.have.property('status', 403)
it('should return a 401', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not terribly important, but as per the comment above the test, I still think 403 is the correct status. How hard would it be to fix?


it('should return a 403', () => {
expect(response).to.have.property('status', 403)
it('should return a 401', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again here I would prefer a 403, since it is good to fend off an attacker at once, but it is even less important than the previous comment, since it is most important to just deny them.

@kjetilk

kjetilk commented Mar 7, 2019

Copy link
Copy Markdown
Member

Two small comments inline, the rest looks good, thanks a lot. :-)

Please feel free to submit a separate PR with the cleanup later!

@kjetilk kjetilk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On second thoughts: Even though I would prefer to have a 403 when a log in wouldn't matter, in the light of the problem #1117 that this is intended to fix, doing that would probably add complexity that is not worth it.

@kjetilk
kjetilk merged commit eb6b62b into release/v5.0.0 Mar 8, 2019
@kjetilk
kjetilk deleted the fix/faulty-403 branch March 8, 2019 21:30
@kjetilk
kjetilk restored the fix/faulty-403 branch March 8, 2019 22:03
michielbdejong added a commit to michielbdejong/node-solid-server that referenced this pull request Mar 12, 2019
kjetilk added a commit that referenced this pull request Mar 15, 2019
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.

4 participants