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

[api] security hardening for microsoft auth #3803

Closed
wants to merge 1 commit into from

Conversation

freemvmt
Copy link
Contributor

@freemvmt freemvmt commented Oct 12, 2024

Ticket: https://trello.com/c/0gYN7cdt

Some changes to improve the security posture of the Microsoft auth flow.

Copy link

github-actions bot commented Oct 12, 2024

Removed vultr server and associated DNS entries

@jessicamcinchak jessicamcinchak marked this pull request as draft October 16, 2024 14:24
@freemvmt freemvmt force-pushed the api-auth-security-hardening branch 4 times, most recently from 2d24531 to fa078d6 Compare October 31, 2024 14:42
@freemvmt freemvmt marked this pull request as ready for review October 31, 2024 14:42
@freemvmt freemvmt changed the title [WIP][api] security hardening for microsoft auth [api] security hardening for microsoft auth Oct 31, 2024
@freemvmt freemvmt requested a review from a team October 31, 2024 15:00
Copy link
Contributor Author

@freemvmt freemvmt left a comment

Choose a reason for hiding this comment

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

Some notes

@@ -112,7 +112,8 @@ assert(process.env.UNIFORM_SUBMISSION_URL);
// needed for storing original URL to redirect to in login flow
app.use(
cookieSession({
maxAge: 24 * 60 * 60 * 100,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

value was previously set at 2.4hrs but I think was supposed to be 24hrs (assuming 100 was intended as 1000), so new value is only a slight reduction, and also clearer to read

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

tokenSet,
done,
): Promise<void> => {
// TODO: use tokenSet.state to pass the redirectTo query param through the auth flow
// TODO: validate id_token sig with the public key from the jwks_uri (...v2.0/keys)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not especially clear how to do this using openid-client v5x, but they completely rewrote the package for v6 and that might offer a clearer route to fetching the keys and verifying the signature

Related task in icebox: https://trello.com/c/7BMpYwyt

@@ -39,7 +39,8 @@ function setJWTCookie(returnTo: string, res: Response, req: Request) {
maxAge: new Date(
new Date().setFullYear(new Date().getFullYear() + 1),
).getTime(),
sameSite: "none",
// the JWT/auth cookies should be sent only between the API server and editor
sameSite: "strict",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please correct me if this doesn't make sense!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be "none" for login to work between the Pizzas and Staging API. Worth rebasing this once #3890 is merged and testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Riiight, that's the motivation for none, I hadn't thought about that case. Although this change should affect both means of authenticating, and Google seems to work on the pizza 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do as you suggest and see what happens

@freemvmt freemvmt force-pushed the api-auth-security-hardening branch 2 times, most recently from fd21b41 to 81aeed5 Compare October 31, 2024 17:22
@DafyddLlyr
Copy link
Contributor

@freemvmt - one thing I just realised here!

The changes to the API files here aren't being run when we're logging into the pizza as we're hitting the staging API for logging in. So that means in order to test this, we need to merge to main and then try to log in on a Pizza.

I'm struggling to find the PR but I'm pretty sure that sameSite: "none" is required from previously trying this out.

@freemvmt
Copy link
Contributor Author

freemvmt commented Nov 1, 2024

The changes to the API files here aren't being run when we're logging into the pizza as we're hitting the staging API for logging in. So that means in order to test this, we need to merge to main and then try to log in on a Pizza.

I'm struggling to find the PR but I'm pretty sure that sameSite: "none" is required from previously trying this out.

@DafyddLlyr that's a great point... I think I'll just take your word for it!

I was testing out lax because we should be sent to staging API via a top level, user-requested navigation step, which I'd expect it to allow, but who knows if that actually works when it's React 🤷🏼 (and I suppose the same does not hold in reverse, crucially)

Aaaand perhaps now isn't the time to find out. I'll swap out for none and we can merge :)

@freemvmt
Copy link
Contributor Author

freemvmt commented Nov 1, 2024

Closed in favour of perfect copy #3895 - @DafyddLlyr please approve that one instead!

@freemvmt freemvmt closed this Nov 1, 2024
@freemvmt freemvmt deleted the api-auth-security-hardening branch December 13, 2024 16:26
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.

2 participants