RFC: Client Certificate Authentication #35533
Replies: 6 comments 4 replies
-
@ealexhaywood any headway on this? |
Beta Was this translation helpful? Give feedback.
-
Is there any update on the matter? |
Beta Was this translation helpful? Give feedback.
-
Personally, I wish this would be given a higher priority. This is appealing for any private use website and business use cases. And, it could be potentially useful during development for when you don’t want anyone snooping your dev-website. Without any support for this in next.js vercel hoisting becomes irrelevant… in addition to the inconvenience of using a custom server Also, in addition to the suggested access / no access behavior of mTLS, it could also be interesting to use client certificates to serve different versions of pages than ones served to anonymous visitors. |
Beta Was this translation helpful? Give feedback.
-
Any update? Need to use PFX certificate with passphrase. Can't find any solution for it. |
Beta Was this translation helpful? Give feedback.
-
Any updates here? Could really use this implementation and can't find a solution. |
Beta Was this translation helpful? Give feedback.
-
Hey all, I haven't done any work towards this, but I have been able to make it work in an environment where TLS client certificate authentication is required:
// alternatively you can use pfx + password as well here
const httpsAgent = new https.Agent({
cert: fs.readFileSync(process.env.PUBLIC_CERTIFICATE_PATH),
key: fs.readFileSync(process.env.PRIVATE_KEY_PATH),
ca: fs.readFileSync(process.env.CA_CHAIN_PATH)
})
axios.get(url, { httpsAgent }) Keep in mind you'll be making this request with the server's TLS credentials. If you are making a request on behalf of a user, you'll need to come up with some sort of mechanism to pass that credential along, like a custom HTTP header, or setting a cookie, both of which you can access with A downside is you can't use native |
Beta Was this translation helpful? Give feedback.
-
Goals
getServerSideProps()
andgetStaticProps()
to services that require client certificate authenticationBackground
Some large enterprise companies and government organizations require client certificate authentication (i.e. two-way TLS) for all internal network traffic. As Next.js currently exists, the only way a developer can achieve this is by using a custom server and configuring it to use an instance of https.Server instead.
The problem is that this opts you out of Automatic Static Optimization and it appears features of the integrated Next router as well:
Depending on the network scale and its geographic locations, a user's connection to the network can be quite slow usually as a result from limited bandwidth or high latency. Getting first class TLS/HTTPS support from Next.js would enable developers building internal systems at these enterprises to deliver next-generation experiences to their users.
Implementation
I am more than happy to take a shot at implementation, opening a PR, and iterating on an acceptable solution with the Next.js maintainers and community. I am open to any and all suggestions for how we can achieve this and I figured you all probably know best (assuming I get the greenlight to go ahead and get started 😆).
I was thinking something along the lines of adding an optional
https
object to some part of thenext.config.js
that allows for some subset oftls.connect()
options to be specified, at a minimum something like this:We would also allow other acceptable values
string[]
(or evenBuffer
/Buffer[]
if your config exports a function) forcert
,key
, andca
. Other config options could also bepfx
andpassphrase
for users who have keystores instead.The idea would be to then pass along these values to dev/production Next.js servers and if the
https
object exists:http
module with thehttps
moduleoptions
to anhttps.Agent
options
tohttps.createServer
I'm not sure what makes the most sense in the context of Next, but I am eager to take a stab at this with some guidance and the go-ahead. It wouldn't let me select the RFC category, but let me know what you think!
Beta Was this translation helpful? Give feedback.
All reactions