-
-
Notifications
You must be signed in to change notification settings - Fork 590
Strict ACL parsing without a regex #2587
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
base: main
Are you sure you want to change the base?
Conversation
|
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.
This definitely looks more performant - a single loop over the string rather than at least 26! However, it's not as clearly correct as it was - the previous code was very obvious and this code is less so - so it will need some unit tests. Just simple assertions that a number of standard permissions strings with/without role, with/without grants parse correctly. Since pg-introspection doesn't seem to have tests already, please use node:test
for them (or mocha/chai if you prefer).
In general we trust permission strings to be valid (we trust Postgres) so I'm not too concerned about malicious permission strings, however Postgres does add new permissions from time to time so it's worth ensuring that the code correctly handles (via an error) a new permission character.
I've included a number of TypeScript improvements, all minor.
} | ||
i++; | ||
} // end token processing | ||
if (i < aclLength) { |
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.
Previously the granter was required, and in general I think it will always be set. Let's just throw an error if it's the empty string.
Description
Supersedes #2586 per maintainer comments.
Motivation: browsing through the code and saw a simple opportunity.
No new tests. Should only require regression testing.
Performance impact
Minor speed improvement for ACL parsing logic in aggregate due to one less regex.
Security impact
Excludes most invalid ACL input. (Doesn't stop duplicate ACL tokens.)
Checklist
yarn lint:fix
passes.yarn test
passes.RELEASE_NOTES.md
file (if one exists).