Fix: Prevent node-forge crash due to unsupported certificate subject attributes#27
Open
NikosRig wants to merge 1 commit into
Open
Conversation
…fields Filters out unknown subject attributes (e.g., jurisdictionC) when generating fake certs with node-forge. This avoids the "Attribute type not specified" error caused by fields not recognized by node-forge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
This PR adds a safeguard when creating fake certificates using the CA. Some real-world certificates include non-standard subject fields (like jurisdictionC, businessCategory, etc.) that node-forge doesn’t recognize. When setSubject() encounters these, it throws an error:
typescript
Copy
Edit
Error: Attribute type not specified.
This PR filters out any unsupported subject fields from the original certificate before passing them to forge, ensuring stable fake certificate generation.
Why it matters
This fixes runtime crashes when intercepting HTTPS requests with such certificates, improving reliability and compatibility of the proxy.
How it's done
Introduces a whitelist of supported name and shortName attributes.
Only those supported by node-forge are passed to cert.setSubject().
✅ Verified that it gracefully skips unknown fields and successfully creates a valid certificate.