For serverless clients, it’s a common pattern to allow users to call UDF only and give UDF admin-like permissions. The injection I’m afraid of can come from not validated args. This is the code I am using.
const _TrimmedString = (value: ExprVal) =>
Let(
{ trimmed: Trim(value) },
If(
Equals(Length(value), Length(Var('trimmed'))),
value,
Abort('TrimmedString'),
),
);
const _NonEmptyString = (value: ExprVal) =>
If(GT(Length(value), 0), value, Abort('NonEmptyString'));
const _Max64String = (value: ExprVal) =>
If(LTE(Length(value), 64), value, Abort('Max64String'));
// const _Max1024String = (value: ExprVal) =>
// If(LTE(Length(value), 1024), value, Abort('Max1024String'));
const _Min6String = (value: ExprVal) =>
If(GTE(Length(value), 6), value, Abort('Min6String'));
const String64 = flow(_TrimmedString, _NonEmptyString, _Max64String);
// All args must be validated, because functions have admin role!
const Arg = (prop: ExprArg, Type: (value: ExprVal) => Expr): Expr =>
pipe(Select(prop, Var('args')), Type);
const ArgRef = (prop: ExprArg): Expr =>
pipe(Select(prop, Var('args')), (value) =>
If(IsRef(value), value, Abort('argRef')),
);
updateViewerName: EitherRight(
Update(ViewerRef(), {
data: {
name: Arg('name', String64),
},
}),
),
But FQL can be tricky I guess. What if someone replaces the string with an FQL expression which does some side effects which evaluate to string? How can we detect that?
In the other words, is my approach correct?