Skip to content

Commit

Permalink
add some minimal checks for external urls in user app dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Dec 27, 2024
1 parent 5ae38f6 commit 362f9e3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion viewer/components/UserAppDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ const SelectExistingDialog=({existingAddons,resolveFunction})=>{
</DialogFrame>
}

const checkUrl=(val,isInternal)=>{
if (! val) return "must not be empty";
if (isInternal){
if (val.match(/^http/i)) return "internal urls must not start with http";
return
}
if (!val.match(/^https*:\/\//i)) return "external urls must start with http[s]://";
}

const UserAppDialog = (props) => {
const [currentAddon, setCurrentAddon] = useState({...props.addon, ...props.fixed});
const dialogContext = useDialogContext();
Expand Down Expand Up @@ -286,6 +295,7 @@ const UserAppDialog = (props) => {
minSize={50}
maxSize={100}
mandatory={(v) => !v}
checkFunction={(v)=>checkUrl(v,false) === undefined}
onChange={(val) => setCurrentAddon({...currentAddon, url: val})}/>
:
<InputReadOnly
Expand Down Expand Up @@ -425,7 +435,9 @@ const UserAppDialog = (props) => {
});

},
{disabled: !currentAddon.icon || !currentAddon.url || !canEdit,close:false})
{
disabled: !currentAddon.icon || !currentAddon.url || !canEdit || checkUrl(currentAddon.url,internal) !== undefined,
close:false})
]}/>
</DialogFrame>
);
Expand Down

0 comments on commit 362f9e3

Please sign in to comment.