Compare commits

..

1 Commits

Author SHA1 Message Date
Balázs Orbán
10bdea24b4 chore(release): bump version 2022-06-28 16:25:29 +00:00
9 changed files with 26 additions and 120 deletions

View File

@@ -93,7 +93,7 @@ The most simple usage is when you want to require authentication for your entire
export { default } from "next-auth/middleware"
```
That's it! Your application is now secured. 🎉
That's it! Your application is not secured. 🎉
If you only want to secure certain pages, export a `config` object with a `matcher`:

View File

@@ -165,12 +165,6 @@ See repository [`README`](https://github.com/nextauthjs/react-query) for more de
NextAuth.js provides a `getSession()` helper which should be called **client side only** to return the current active session.
On the server side, **this is still available to use**, however, we recommend using `unstable_getServerSession` going forward. The idea behind this is to avoid an additional unnecessary `fetch` call on the server side. For more information, please check out [this issue](https://github.com/nextauthjs/next-auth/issues/1535).
:::note
The `unstable_getServerSession` only has the prefix `unstable_` at the moment, because the API may change in the future. There are no known bugs at the moment and it is safe to use. If you discover any issues, please do report them as a [GitHub Issue](https://github.com/nextauthjs/next-auth/issues) and we will patch them as soon as possible.
:::
This helper is helpful in case you want to read the session outside of the context of React.
When called, `getSession()` will send a request to `/api/auth/session` and returns a promise with a [session object](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/core/types.ts#L407-L425), or `null` if no session exists.

View File

@@ -58,7 +58,7 @@ More details can be found [here](https://next-auth.js.org/configuration/nextjs#m
You can protect server side rendered pages using the `unstable_getServerSession` method. This is different from the old `getSession()` method, in that it does not do an extra fetch out over the internet to confirm data from itself, increasing performance significantly.
You need to add this to every server rendered page you want to protect. Be aware, `unstable_getServerSession` takes slightly different arguments than the method it is replacing, `getSession`.
You need to add this to every server rendered page you want to protect.
```js title="pages/server-side-example.js"
import { useSession, unstable_getServerSession } from "next-auth/next"
@@ -82,11 +82,7 @@ export default function Page() {
export async function getServerSideProps(context) {
return {
props: {
session: await unstable_getServerSession(
context.req,
context.res,
authOptions
),
session: await unstable_getServerSession(context.req, context.res, authOptions),
},
}
}

View File

@@ -166,10 +166,6 @@ export default function App({
}
```
## Security
If you think you have found a vulnerability (or not sure) in NextAuth.js or any of the related packages (i.e. Adapters), we ask you to have a read of our [Security Policy](https://github.com/nextauthjs/next-auth/blob/main/SECURITY.md) to reach out responsibly. Please do not open Pull Requests/Issues/Discussions before consulting with us.
## Acknowledgments
[NextAuth.js is made possible thanks to all of its contributors.](https://next-auth.js.org/contributors)

View File

@@ -1,6 +1,6 @@
{
"name": "next-auth",
"version": "4.8.0",
"version": "4.7.0",
"description": "Authentication for Next.js",
"homepage": "https://next-auth.js.org",
"repository": "https://github.com/nextauthjs/next-auth.git",
@@ -138,4 +138,4 @@
"**/tests",
"**/__tests__"
]
}
}

View File

@@ -9,7 +9,6 @@ import { SessionStore } from "./lib/cookie"
import type { NextAuthAction, NextAuthOptions } from "./types"
import type { Cookie } from "./lib/cookie"
import type { ErrorType } from "./pages/error"
import { parse as parseCookie } from "cookie"
export interface RequestInternal {
/** @default "http://localhost:3000" */
@@ -69,7 +68,7 @@ async function toInternalRequest(
method: req.method,
headers,
body: await getBody(req),
cookies: parseCookie(req.headers.get("cookie") ?? ""),
cookies: {},
providerId: nextauth[1],
error: url.searchParams.get("error") ?? nextauth[1],
host: detectHost(headers["x-forwarded-host"] ?? headers.host),

View File

@@ -30,25 +30,12 @@ export default async function signin(params: {
return { redirect: `${url}/error?error=OAuthSignin` }
}
} else if (provider.type === "email") {
/**
* @note Technically the part of the email address local mailbox element
* (everything before the @ symbol) should be treated as 'case sensitive'
* according to RFC 2821, but in practice this causes more problems than
* it solves. We treat email addresses as all lower case. If anyone
* complains about this we can make strict RFC 2821 compliance an option.
*/
let email = body?.email?.toLowerCase()
if (!email) return { redirect: `${url}/error?error=EmailSignin` }
email = email
.split(",")[0]
.trim()
.replaceAll("&", "&")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#x27;")
// Note: Technically the part of the email address local mailbox element
// (everything before the @ symbol) should be treated as 'case sensitive'
// according to RFC 2821, but in practice this causes more problems than
// it solves. We treat email addresses as all lower case. If anyone
// complains about this we can make strict RFC 2821 compliance an option.
const email = body?.email?.toLowerCase() ?? null
// Verified in `assertConfig`
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

View File

@@ -1,59 +0,0 @@
import { createCSRF, handler } from "./lib"
import EmailProvider from "../src/providers/email"
const originalEmail = "balazs@email.com"
test.each([
[originalEmail, `,<a href="example.com">Click here!</a>`],
[originalEmail, ""],
])("Sanitize email", async (emailOriginal, emailCompromised) => {
const sendEmail = jest.fn()
const { secret, csrf } = createCSRF()
const email = {
original: emailOriginal,
compromised: `${emailOriginal}${emailCompromised}`,
}
const { res } = await handler(
{
providers: [EmailProvider({ sendVerificationRequest: sendEmail })],
adapter: {
getUserByEmail: (email) => ({ id: "1", email, emailVerified: null }),
createVerificationToken: (token) => token,
} as any,
secret,
},
{
prod: true,
path: "signin/email",
requestInit: {
method: "POST",
body: JSON.stringify({
email: email.compromised,
csrfToken: csrf.value,
}),
headers: { "Content-Type": "application/json", Cookie: csrf.cookie },
},
}
)
if (!emailCompromised) {
expect(res.redirect).toBe(
"http://localhost:3000/api/auth/verify-request?provider=email&type=email"
)
expect(sendEmail).toHaveBeenCalledWith(
expect.objectContaining({
identifier: email.original,
token: expect.any(String),
})
)
} else {
expect(res.redirect).not.toContain("error=EmailSignin")
const emailTo = sendEmail.mock.calls[0][0].identifier
expect(emailTo).not.toBe(email.compromised)
expect(emailTo).toBe(email.original)
}
})

View File

@@ -1,4 +1,3 @@
import { createHash } from "crypto"
import type { LoggerInstance, NextAuthOptions } from "../src"
import { NextAuthHandler } from "../src/core"
@@ -8,16 +7,17 @@ export const mockLogger: () => LoggerInstance = () => ({
debug: jest.fn(() => {}),
})
interface HandlerOptions {
prod?: boolean
path?: string
params?: URLSearchParams | Record<string, string>
requestInit?: RequestInit
}
export async function handler(
options: NextAuthOptions,
{ prod, path, params, requestInit }: HandlerOptions
{
prod,
path,
params,
}: {
prod?: boolean
path?: string
params?: URLSearchParams | Record<string, string>
}
) {
// @ts-ignore
if (prod) process.env.NODE_ENV = "production"
@@ -27,7 +27,11 @@ export async function handler(
params ?? {}
)}`
)
const req = new Request(url, { headers: { host: "" }, ...requestInit })
const req = new Request(url, {
headers: {
host: "",
},
})
const logger = mockLogger()
const response = await NextAuthHandler({
req,
@@ -45,14 +49,3 @@ export async function handler(
log: logger,
}
}
export function createCSRF() {
const secret = "secret"
const value = "csrf"
const token = createHash("sha256").update(`${value}${secret}`).digest("hex")
return {
secret,
csrf: { value, token, cookie: `next-auth.csrf-token=${value}|${token}` },
}
}