Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { toSafeHttpUrl } from './safeUrl.js';
|
||||
|
||||
test('toSafeHttpUrl keeps absolute http(s) urls only', () => {
|
||||
assert.equal(
|
||||
toSafeHttpUrl(' https://ai.example.com/ '),
|
||||
'https://ai.example.com/',
|
||||
);
|
||||
assert.equal(toSafeHttpUrl('http://10.0.0.5:8080'), 'http://10.0.0.5:8080');
|
||||
for (const bad of [
|
||||
'',
|
||||
null,
|
||||
undefined,
|
||||
42,
|
||||
'javascript:alert(1)',
|
||||
'JAVASCRIPT:alert(1)',
|
||||
'data:text/html,x',
|
||||
'file:///etc/passwd',
|
||||
'//evil.example.com',
|
||||
'/relative/path',
|
||||
'ai.example.com',
|
||||
'https://',
|
||||
'https://user:pw@ai.example.com',
|
||||
]) {
|
||||
assert.equal(toSafeHttpUrl(bad), '', `${bad} must be rejected`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user