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

Change token path authentication to /PROJECT/join/TOKEN #843

Merged
merged 5 commits into from Oct 13, 2021

Conversation

Glandos
Copy link
Member

@Glandos Glandos commented Oct 10, 2021

See #802 for initial conversation.

I left project_id/token since we need to validate that the project exist before validating the token.

Otherwise, it means extracting it from the token without verifying the signature in a first step, and I'm not comfortable with this. With this, the project is checked with pull_project preprocessor, as every other endpoint.

Discussion is opened 😄

@almet
Copy link
Member

almet commented Oct 10, 2021

Thanks for opening a new discussion on this.

Otherwise, it means extracting it from the token without verifying the signature in a first step, and I'm not comfortable with this.

Could you please elaborate on why this would be bad from your standpoint? Thanks :-)

If the URL is related to a project id, then the name could be {project_id}/join/{token} (or without {project_id} if we decide against it)

@almet
Copy link
Member

almet commented Oct 10, 2021

If the URL is related to a project id, then the name could be {project_id}/join/{token} (or without {project_id} if we decide against it)

Disregard this, I haven't understood this was a pull request with code attached and was thinking about it the wrong way.

I find it a bit hackish to check on the dot in the URL, but that could work!

@Glandos
Copy link
Member Author

Glandos commented Oct 10, 2021

@almet commented on 10 oct. 2021, 16:34 UTC+2:>

Otherwise, it means extracting it from the token without verifying the signature in a first step, and I'm not comfortable with this.

Could you please elaborate on why this would be bad from your standpoint? Thanks :-)

When deserializing, URLSafeSerializer will throw an exception BadSignature. I used to call loads twice, one without the password to get the project, and another one with the password after fetching it from the database, but it seems hackish.
However, the result nowadays is that I had to escape some other things:

  • The pull_project that has a built in check for "authenticate"
  • Redirection to .authenticate if the token is invalid
  • Redundant data/project in verify_token

Regarding the path, I have mixed feeling:

  • /join/<token> is much easier to handle, but it will broke on existing installation with a project join (silly, isn't it?)
  • /project_id/<token> needs a hack, otherwise it's a catchall.
  • /project_id/join/<token> is best from the developer point of view, but it's a long URL…

@almet
Copy link
Member

almet commented Oct 10, 2021

I feel we should go this way with /join. The odds that this is used are fairly low in my opinion. I see two ways to solve this :

  • Create a migration in the database to see if the "join" project exists, and if so tell the operator to do something about it. We could even migrate it to another name and send en email to the contact email of the "join" project ;
  • When /join is used without a token, redirect to the project page. That could be the simpler solution, because /join without anything after is not used, only /join/{token}.

But… whatever works! :-)

@Glandos
Copy link
Member Author

Glandos commented Oct 10, 2021

@almet commented on 10 oct. 2021, 22:02 UTC+2:

  • When /join is used without a token, redirect to the project page. That could be the simpler solution, because /join without anything after is not used, only /join/{token}.

In this case we need to keep the regexp converter for /join/settle_bills, /join/statistics and all other subpaths for a project. I am really lacking an argument to decide a best solution here :)

@zorun
Copy link
Collaborator

zorun commented Oct 10, 2021

I feel like /<project_id>/join/<token> is the most clear and clean way. In the other solutions, I don't like this check for a dot in the middle.

If you think it's too long, just shorten join to j?

@almet
Copy link
Member

almet commented Oct 10, 2021

Or it could mean that we need to change the URL structure altogether but… yeah, this would kinda suck. Sorry for making this wrong choice in the first place.

I feel like /<project_id>/join/ is the most clear and clean way.

Okay, I think I'm coming to the same conclusion. I would be against the /j. After all explicit is better than implicit :-)

this remove the need for the regex route converter. Nice.
@Glandos
Copy link
Member Author

Glandos commented Oct 10, 2021

OK, done, I think it can be merged.

Copy link
Member

@almet almet left a comment

Choose a reason for hiding this comment

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

It looks good. I would change the name of the route though. Cheers!

ihatemoney/web.py Outdated Show resolved Hide resolved
ihatemoney/web.py Outdated Show resolved Hide resolved
@Glandos
Copy link
Member Author

Glandos commented Oct 10, 2021

The last change here is on invalid token. At first, I mimic the old behavior by redirecting to the authentication form, but it was error prone from both the code and the user point of view.
Instead, let's redirect to the home with a flash message.

@Glandos
Copy link
Member Author

Glandos commented Oct 13, 2021

Tests are using a lot of CPU an (wo)manpower, but sometimes, you know it worth it.

@Glandos Glandos changed the title Change token path authentication to /PROJECT/token Change token path authentication to /PROJECT/join/TOKEN Oct 13, 2021
@Glandos Glandos merged commit 7d92267 into spiral-project:master Oct 13, 2021
@Glandos Glandos deleted the invite_link branch October 13, 2021 20:00
TomRoussel pushed a commit to TomRoussel/ihatemoney that referenced this pull request Mar 2, 2024
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.

None yet

3 participants