Skip to content

Commit e244223

Browse files
committed
- added mini app content archive checksum validation
- added relative url resolving for remote app content and app icon - fixed fetched mini app newline parsing issue
1 parent 06ecf4b commit e244223

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

Spixi/MiniApps/MiniApp.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using IXICore;
2-
using System.Linq;
32
using System.Text;
43

54
namespace SPIXI.MiniApps
@@ -30,7 +29,7 @@ public class MiniApp
3029
public byte[] signature = null;
3130
public Dictionary<MiniAppCapabilities, bool> capabilities = null;
3231

33-
public MiniApp(string[] app_info)
32+
public MiniApp(string[] app_info, string? app_url = null)
3433
{
3534
foreach (string command in app_info)
3635
{
@@ -110,6 +109,31 @@ public MiniApp(string[] app_info)
110109
break;
111110
}
112111
}
112+
113+
// If an app url is provided, this app metadata is likely from a remote source
114+
if (app_url != null)
115+
{
116+
// Attempt to resolve relative URLs
117+
if (!contentUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase))
118+
{
119+
int last_index = app_url.LastIndexOf('/');
120+
if (last_index != -1)
121+
{
122+
contentUrl = app_url.Substring(0, last_index + 1) + contentUrl;
123+
}
124+
125+
}
126+
127+
if (!image.StartsWith("http", StringComparison.OrdinalIgnoreCase))
128+
{
129+
int last_index = app_url.LastIndexOf('/');
130+
if (last_index != -1)
131+
{
132+
image = app_url.Substring(0, last_index + 1) + image;
133+
}
134+
}
135+
}
136+
113137
}
114138

115139
private Dictionary<MiniAppCapabilities, bool> parseCapabilities(string value)

Spixi/MiniApps/MiniAppManager.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public void stop()
104104
}
105105

106106
string content = Encoding.UTF8.GetString(data);
107-
string[] app_info = content.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
107+
string[] app_info = content.Replace("\r\n", "\n").Split('\n');
108108

109-
return new MiniApp(app_info);
109+
return new MiniApp(app_info, url);
110110
}
111111
catch (HttpRequestException e)
112112
{
@@ -138,6 +138,12 @@ public string install(MiniApp fetchedAppInfo)
138138
{
139139
File.WriteAllBytes(source_app_file_path, client.GetByteArrayAsync(fetchedAppInfo.contentUrl).Result);
140140
fetchedAppInfo.contentSize = new FileInfo(source_app_file_path).Length;
141+
string file_checksum = Crypto.sha256(source_app_file_path);
142+
143+
if (file_checksum != fetchedAppInfo.checksum)
144+
{
145+
throw new InvalidOperationException($"Checksum mismatch for downloaded app file. Expected {fetchedAppInfo.checksum} got {file_checksum}");
146+
}
141147
}
142148
catch (Exception e)
143149
{

0 commit comments

Comments
 (0)