Skip to content

fix: catch invalid url early #932

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

Merged
merged 3 commits into from
Apr 13, 2025
Merged

fix: catch invalid url early #932

merged 3 commits into from
Apr 13, 2025

Conversation

avallete
Copy link
Member

What kind of change does this PR introduce?

  • Catch if there is an invalid pg url early on in the request processing and unify the error message

Related: PGMETA-53

@avallete avallete requested review from a team as code owners April 11, 2025 11:20
Comment on lines +31 to +46
const encryptedHeader = request.headers['x-connection-encrypted']?.toString()
if (encryptedHeader) {
try {
request.headers.pg = CryptoJS.AES.decrypt(encryptedHeader, CRYPTO_KEY)
.toString(CryptoJS.enc.Utf8)
.trim()
} catch (e: any) {
request.log.warn({
message: 'failed to parse encrypted connstring',
error: e.toString(),
})
throw new Error('failed to process upstream connection details')
}
} else {
request.headers.pg = PG_CONNECTION
}
Copy link
Member Author

Choose a reason for hiding this comment

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

note

To identify why and how this happen, would it be okay to console.error the x-connection-encrypted ?

Copy link
Member

Choose a reason for hiding this comment

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

I think no, safer not to log any potentially sensitive information

@coveralls
Copy link

Pull Request Test Coverage Report for Build 14401988114

Details

  • 21 of 27 (77.78%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 75.699%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/server/routes/index.ts 21 27 77.78%
Totals Coverage Status
Change from base Build 14390916667: 0.1%
Covered Lines: 5003
Relevant Lines: 6531

💛 - Coveralls

@avallete avallete merged commit c353582 into master Apr 13, 2025
5 checks passed
@avallete avallete deleted the fix/catch-invalid-url-early branch April 13, 2025 12:55
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.

3 participants