-
Notifications
You must be signed in to change notification settings - Fork 51
Adds console disclaimer when running direct sql from the browser #158
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9156de6
Adds console disclaimer when running direct sql from the browser
lneves12 bc063de
adds warning to websocket as well
lneves12 2f5490d
Adds config to disable the warning
lneves12 c4e3be4
rename option and improve warning message
lneves12 ac167c9
use neonConfig option as well for http
lneves12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ | |
|
|
||
| node_modules | ||
| build | ||
| /.idea | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,20 @@ circumstances are right. | |
| import type { ClientBase as PgClientBase } from 'pg'; | ||
| import { type SocketDefaults } from './shims/net'; | ||
|
|
||
| // Ensure we are very explicit while using these apis. This ensures more type safety | ||
| // specially since this library is made to run both in the browser and node.js environments. | ||
| declare global { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was mainly to avoid adding dom types globally to the tsconfig. It makes it more type safe |
||
| const window: Window | undefined; | ||
| const document: Document | undefined; | ||
|
|
||
| interface Window {} | ||
| interface Document {} | ||
| } | ||
|
|
||
| export * from './httpQuery'; | ||
| export * from './sqlTemplate'; | ||
| export type * from './httpTypes'; | ||
| export * from './utils'; | ||
|
|
||
| export { NeonPool as Pool, type NeonPoolClient as PoolClient } from './pool'; | ||
| export { NeonClient as Client } from './client'; | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Detects if the code is running in a browser environment and displays a warning | ||
| * about the security implications of running SQL directly from the browser. | ||
| */ | ||
| export function warnIfBrowser(): void { | ||
| const isBrowser = | ||
| typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
| if ( | ||
| isBrowser && | ||
| typeof console !== 'undefined' && | ||
| typeof console.warn === 'function' | ||
| ) { | ||
| console.warn(` | ||
| ************************************************************ | ||
| * * | ||
| * WARNING: Running SQL directly from the browser can have * | ||
| * security implications. Even if your database is * | ||
| * protected by Row-Level Security (RLS), use it at your * | ||
| * own risk. This approach is great for fast prototyping, * | ||
| * but ensure proper safeguards are in place to prevent * | ||
| * misuse or execution of expensive SQL queries by your * | ||
| * end users. * | ||
| * * | ||
lneves12 marked this conversation as resolved.
Show resolved
Hide resolved
lneves12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * If you've assessed the risks, suppress this message * | ||
| * using the disableWarningInBrowsers configuration * | ||
| * parameter. * | ||
| * * | ||
| ************************************************************`); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the option is not specified here, do we inherit from the global configuration parameter? I think we probably should.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it makes sense. The implementation is a bit weird, because neonConfig in reality is a socket config that we don't use for the http client, but I guess this is good enough (already updated)