Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@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
The npm package @macfja/sveltekit-cas receives a total of 2 weekly downloads. As such, @macfja/sveltekit-cas popularity was classified as not popular.
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.