
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
@macfja/sveltekit-cas
Advanced tools
A set of functions to ease usage of a CAS/SSO in SvelteKit
npm install --save @macfja/sveltekit-cas
Protect all pages that start with /profile/
and only allow user to go on his own page (/profile/my-cool-username
) and fill the session with the token (or null
) to provide to endpoints and the username of the connected user (or null
)
// src/hooks.js
import { casHandler, getSessionToken, getSessionUser } from "@macfja/sveltekit-cas"
export async function handle({ request, resolve }) {
return (
(await casHandler(
(request) => request.path.startsWith("/profile/"),
(request, user) => {
const regexp = request.path.match(/\/profile\/(\w+)/)
return user !== regexp[1]
},
request
)) || resolve(request)
)
}
export function getSession(request) {
return {
...getSessionToken(request),
...getSessionUser(request)
}
}
Protect endpoint, so only connected user can access it
// src/routes/api/user.js
import { validate, validateUser } from "@macfja/sveltekit-cas"
export async function post({ headers }: ServerRequest): Promise<EndpointOutput> {
const token = headers.token ?? null
const access = validateUser(token, "admin")
if (access !== null) {
return access
}
// ... Do operation that only the user `admin` can do
}
export async function get({ headers }: ServerRequest): Promise<EndpointOutput> {
const token = headers.token ?? null
const access = validate(token)
if (access !== null) {
return access
}
// ... Do operation that only connected user can do
}
The package have several configuration.
They are all have to be set as environment variables
Name | Default | Comment |
---|---|---|
PUBLIC_HOST | no default, value is required | Public server domain name |
PUBLIC_PORT | 443 | Public server port |
CAS_HOST | no default, value is required | Host of the SSO server |
CAS_PORT | 443 | Port of the SSO server |
CAS_SESSION_COOKIE | session | The name of the cookie that will contain the JWT session |
JWT_ISS | sveltekit-cas | The issuer of the JWT token |
JWT_SECRET | changeme | The key used to generate the token signature |
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Read more in the Contributing file
The MIT License (MIT). Please see License File for more information.
[1.0.0]
First version
FAQs
CAS/SSO integration in SvelteKit
We found that @macfja/sveltekit-cas demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.