fix: 修复 UI Schema 导航路径遍历漏洞
This commit is contained in:
@@ -2,10 +2,20 @@ bool isValidInternalNavigationPath(String path) {
|
|||||||
if (path.isEmpty || !path.startsWith('/')) {
|
if (path.isEmpty || !path.startsWith('/')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (path.contains('%')) {
|
||||||
|
try {
|
||||||
|
if (Uri.decodeComponent(path) != path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return !path.startsWith('//') &&
|
return !path.startsWith('//') &&
|
||||||
!path.contains('://') &&
|
!path.contains('://') &&
|
||||||
!path.contains('?') &&
|
!path.contains('?') &&
|
||||||
!path.contains('#') &&
|
!path.contains('#') &&
|
||||||
|
!path.contains('..') &&
|
||||||
!path.contains(':');
|
!path.contains(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +30,7 @@ String buildUiSchemaNavigationTarget({
|
|||||||
for (final entry in params.entries) {
|
for (final entry in params.entries) {
|
||||||
final value = entry.value;
|
final value = entry.value;
|
||||||
if (value is String && value.isNotEmpty) {
|
if (value is String && value.isNotEmpty) {
|
||||||
queryParams[entry.key] = value;
|
queryParams[entry.key] = _sanitizeQueryValue(value);
|
||||||
} else if (value is num || value is bool) {
|
} else if (value is num || value is bool) {
|
||||||
queryParams[entry.key] = value.toString();
|
queryParams[entry.key] = value.toString();
|
||||||
}
|
}
|
||||||
@@ -33,3 +43,7 @@ String buildUiSchemaNavigationTarget({
|
|||||||
);
|
);
|
||||||
return targetUri.toString();
|
return targetUri.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _sanitizeQueryValue(String value) {
|
||||||
|
return value.replaceAll('\n', ' ').replaceAll('\r', '').trim();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user