casbin / node-casbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser

Home Page:https://casbin.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem "invalid group" with v5.24.4 and later

IonVillarreal opened this issue Β· comments

Hi I updated the library to the latest version and I got this error which seems to be caused by #439 in version 5.24.4

Attached the capture of the error in NextJS

Captura de pantalla 2023-03-23 a la(s) 17 11 23

Someone else happens ? I'll stay on version 5.24.3

Could you provide your case?

@IonVillarreal plz provide the full code, Casbin model, policy, request and response (expected and got)

Hi, sorry for the delay, I attached the snippet of the code where the error happened

import Head from "next/head";
import Image from "next/image";
import { Inter } from "next/font/google";
import styles from "@/styles/Home.module.css";
import { useEffect } from "react";
import {
  Enforcer,
  newEnforcer,
  newModelFromString,
  StringAdapter,
} from "casbin";


export const basicModel = `
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = (r.sub == p.sub || p.sub == "*") && keyMatch2(r.obj, p.obj) && regexMatch(r.act, p.act)
`;
export const basicPolicy = `g, admin, ADMINISTRADOR`;

export default function Home() {
  const iniciar = async () => {
    const politicas: string[][] = []; // TODO: add
    const model = newModelFromString(basicModel);
    const policy = new StringAdapter(basicPolicy);
    const enforcerTemp: Enforcer = await newEnforcer(model, policy);
    for await (const p of politicas) {
      await enforcerTemp.addPolicy(p[0], p[1], p[2], p[3], p[4], p[5]);
    }
    return enforcerTemp;
  };

  useEffect(() => {
    iniciar();
  }, []);

  return (
    <>
      <Head>
        <title>Create Next App</title>
      </Head>
      <main className={styles.main}>
        <div className={styles.description}>
          <div>
            <a
              href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
              target="_blank"
              rel="noopener noreferrer"
            >
              By{" "}
              <Image
                src="/vercel.svg"
                alt="Vercel Logo"
                className={styles.vercelLogo}
                width={100}
                height={24}
                priority
              />
            </a>
          </div>
        </div>
      </main>
    </>
  );
}

image

The error happens in Safari v16.3, but not happen in Safari v16.4 that released today

It still happens in v5.26.0 in Safari v16.3 but it doesn't happen in Safari v16.4

@johnsonjo4531 please take a look as it is caused by: #439

Yes, this is definitely my fault πŸ˜…. I used an ES2018 feature RegExp Negative LookBehind to implement the two lines of RegExp I used in my PR. I should have let you all know that it wouldn't work on older browsers. It should work on all modern (non End Of Life) Node.js versions though as far as I'm aware. I don't have much time to assist with the fix. But these two lines in ./src/util/util.ts are what need to be changed to not use back references. If they are changed back to what they used to be they will fail the tests I added to fix the bug in #438. See this series of answers on stack overflow for possible answers to not use the negative lookbehind.

@hsluoyz hopefully the above is enough info to get you guys going. I'll try to help you tomorrow if you can't get this by then just ping me, thanks.

@johnsonjo4531 I think we need your PR:) Thanks for doing this

πŸŽ‰ This issue has been resolved in version 5.26.1 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€