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

NextJS Accelerate Starter - Insecure random quote endpoint #6963

Open
dansholds opened this issue Oct 30, 2024 · 0 comments
Open

NextJS Accelerate Starter - Insecure random quote endpoint #6963

dansholds opened this issue Oct 30, 2024 · 0 comments

Comments

@dansholds
Copy link

Hey team,

When using the nextjs-starter project in the accelerate directory, I was getting failures when attempting to add a new quote to the DB.

It was only when checking out the endpoint in the browser and wrapping my POST request with better error handling that I was able to see this:

export async function POST(request: Request) {
  try {
    const response = await fetch('https://api.quotable.io/random', {
      cache: 'no-cache',
    })

    if (!response.ok) {
      throw new Error(`Fetch error: ${response.status} ${response.statusText}`)
    }

    const data = await response.json()
    await addQuote(data.content)

    return new Response(JSON.stringify({ quote: data.content }), {
      headers: { 'Content-Type': 'application/json' },
      status: 201,
    })
  } catch (error) {
    console.error('Error in POST request:', error)
    return new Response(
      JSON.stringify({ error: 'Failed to fetch or add quote.' }),
      {
        headers: { 'Content-Type': 'application/json' },
        status: 500,
      },
    )
  }
}

This can be negated in development by just setting export NODE_TLS_REJECT_UNAUTHORIZED='0' but I thought I'd let you know! Happy to submit a PR for the docs.

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

No branches or pull requests

1 participant