@certik/encrypt-decrypt-ssr
v2.0.1
Published
Package for a fake server side props encryption in Next.js
Keywords
Readme
Encryption/Decryption for SSR NEXT_DATA
Description
In NEXT_DATA, important data is stored in order to hydrate the page during server side rendering.
We cannot remove NEXT_DATA as it is required, but it leaves us vulnerable to data crawlers and scrapers who can publically access the data.
This library can be used to encrypt NEXT_DATA pageProps during getStaticProps and getServerSideProps data fetching and to decrypt it in default page components.
This method is not meant to be used for actual security purposes as the encryption key is stored in the environment variables and can be easily accessed by attackers, but it can be used to obfuscate data and prevent data crawlers and scrapers from easily accessing the data.
Install
Run the following command to install:
bun add @certik/encrypt-decrypt-ssrUsage
For default page component:
import { withSSRDecrypt } from "@certik/encrypt-decrypt-ssr";
// Wrap the default page component alongside the secret encrypt key to decrypt and use the encrypted NEXT_DATA page props
function PageComponent({ ... }) {
...
}
export default withSSRDecrypt(PageComponent);For server side:
import { withEncryptSSR } from "@certik/encrypt-decrypt-ssr";
// Wrap getStaticProps or getServerSideProps data fetching functions
export const getStaticProps: GetStaticProps = withEncryptSSR(async () => { ... });
or
export const getServerSideProps: GetServerSideProps = withEncryptSSR(async () => { ... });Development
Edit source code in /src directory. Support Javascript, Typescript, JSX, and TSX.
Linting and Formatting
bun lint
bun formatPublish
Compile source code by running:
bun buildThen publish package:
bun publish --access public